산업 제조
산업용 사물 인터넷 | 산업자재 | 장비 유지 보수 및 수리 | 산업 프로그래밍 |
home  MfgRobots >> 산업 제조 >  >> Industrial programming >> MATLAB

MATLAB 대수 방정식 풀이: solve, simplify, factor 완전 정복

MATLAB에서 기본 대수 방정식 풀기

solve 함수는 대수 방정식을 풉니다. 가장 간단한 형태는 방정식을 따옴표로 감싸 인수로 전달하는 것입니다.

예제: x - 5 = 0 풀기

solve('x-5=0')

결과: ans = 5

변수에 저장: y = solve('x-5 = 0') → y = 5

우변 생략 가능: solve('x-5') → ans = 5

여러 심볼이 있을 때 변수 지정

solve(equation, variable)

예: v - u - 3*t^2 = 0을 v에 대해 풀기

solve('v-u-3*t^2=0', 'v')

결과: ans = 3*t^2 + u

Octave에서 기본 방정식 풀기

Octave는 roots 함수를 사용합니다. 계수 벡터를 인수로 줍니다.

roots([1, -5])  % x - 5 = 0 → 계수 [1, -5]

결과: ans = 5

이차방정식 풀기 (MATLAB)

solve는 고차 방정식도 풀 수 있으며, 근을 배열로 반환합니다.

eq = 'x^2 -7*x + 12 = 0';
s = solve(eq);
disp('The first root is: '), disp(s(1));
disp('The second root is: '), disp(s(2));

결과:

The first root is: 3
The second root is: 4

이차방정식 풀기 (Octave)

s = roots([1, -7, 12]);
disp('The first root is: '), disp(s(1));
disp('The second root is: '), disp(s(2));

결과: 4, 3 (순서 다를 수 있음)

고차 방정식 풀기 (MATLAB)

삼차 방정식: (x-3)^2*(x-7)=0

solve('(x-3)^2*(x-7)=0')

결과: ans = 3, 3, 7 (중근 포함)

4차 방정식: x^4 - 7x^3 + 3x^2 - 5x + 9 = 0

eq = 'x^4 - 7*x^3 + 3*x^2 - 5*x + 9 = 0';
s = solve(eq);
disp('The first root is: '), disp(s(1));
disp('The second root is: '), disp(s(2));
disp('The third root is: '), disp(s(3));
disp('The fourth root is: '), disp(s(4));
% 수치화
disp('Numeric value of first root'), disp(double(s(1)));
disp('Numeric value of second root'), disp(double(s(2)));
disp('Numeric value of third root'), disp(double(s(3)));
disp('Numeric value of fourth root'), disp(double(s(4)));

결과 (수치):

6.6304
1.0598
-0.3451 - 1.0778i
-0.3451 + 1.0778i
마지막 두 근은 복소수입니다.

고차 방정식 풀기 (Octave)

v = [1, -7, 3, -5, 9];
s = roots(v);
disp('Numeric value of first root'), disp(double(s(1)));
disp('Numeric value of second root'), disp(double(s(2)));
disp('Numeric value of third root'), disp(double(s(3)));
disp('Numeric value of fourth root'), disp(double(s(4)));

연립방정식 풀기 (MATLAB)

solve로 다변수 연립방정식도 해결 가능.

s = solve('5*x + 9*y = 5', '3*x - 6*y = 4');
s.x
s.y

결과: x = 22/19, y = -5/57

3변수 연립방정식 예:

x + 3y - 2z = 5
3x + 5y + 6z = 7
2x + 4y + 3z = 8

solve에 방정식 문자열들을 나열하면 됩니다.

연립방정식 풀기 (Octave)

행렬 형태 A*x = b로 변환 후 A \ b로 풉니다.

A = [5, 9; 3, -6];
b = [5; 4];
A \ b

결과: x ≈ 1.1579, y ≈ -0.0877

방정식 전개(expand) 및 수집(collect) - MATLAB

syms로 심볼릭 변수 선언 후 사용.

syms x y
expand((x-5)*(x+9))
expand((x+2)*(x-3)*(x-5)*(x+7))
expand(sin(2*x))
expand(cos(x+y))
collect(x^3*(x-7))
collect(x^4*(x-3)*(x-5))

결과:

x^2 + 4*x - 45
x^4 + x^3 - 43*x^2 + 23*x + 210
2*cos(x)*sin(x)
cos(x)*cos(y) - sin(x)*sin(y)
x^4 - 7*x^3
x^6 - 8*x^5 + 15*x^4

방정식 전개/수집 - Octave (symbolic 패키지 필요)

pkg load symbolic
symbols
x = sym('x'); y = sym('y'); z = sym('z');
expand((x-5)*(x+9))
expand((x+2)*(x-3)*(x-5)*(x+7))
expand(Sin(2*x))
expand(Cos(x+y))
collect(x^3*(x-7), z)
collect(x^4*(x-3)*(x-5), z)

인수분해(factor) 및 단순화(simplify)

syms x y
factor(x^3 - y^3)
factor([x^2-y^2, x^3+y^3])
simplify((x^4-16)/(x^2-4))

결과:

(x - y)*(x^2 + x*y + y^2)
[ (x - y)*(x + y), (x + y)*(x^2 - x*y + y^2) ]
x^2 + 4

MATLAB

  1. MATLAB: 선도적인 수치 연산 환경 종합 개요
  2. MATLAB 기초 마스터: 필수 구문 및 명령어
  3. MATLAB 변수 이해: 기초와 예제
  4. 효율적인 계산을 위한 필수 MATLAB 명령어
  5. MATLAB 데이터 타입 완벽 가이드: 종류, 변환, 확인 방법
  6. MATLAB 연산자 마스터: 산술, 논리, 비트 연산 완벽 가이드
  7. MATLAB 벡터 마스터: 행 벡터와 열 벡터 기초
  8. MATLAB 행렬 기초 마스터: 생성, 참조, 데이터 조작
  9. MATLAB: 다차원 배열과 특수 배열 마스터하기
  10. MATLAB 콜론 연산자 마스터하기: 벡터 생성과 효율적 반복