How to solve two simultaneous equations using solve command?

조회 수: 18 (최근 30일)
Jen Cong Wong
Jen Cong Wong 2017년 12월 12일
댓글: Jen Cong Wong 2017년 12월 14일
I want to solve these two simultaneous equations:
eqn1 = 0.75*k*B1^3 + 0.75*k*B1*B2^2 - m*w^2*B1 + c*B1 -D*w*B2- A == 0
eqn2 = 0.75*k*B2^3 + 0.75*k*B2*B1^2 - m*w^2*B2 + c*B2 -D*w*B1 == 0
and find what is the (B1^2+B2^2)^(1/2) (square root of B1 squared plus B2 squared ) and also plot the (B1^2+B2^2)^(1/2) Vs w.
So far I wrote my code until here and i dont know how to continue:
syms A m c k w D B1 B2
eqn1 = 0.75*k*B1^3 + 0.75*k*B1*B2^2 - m*w^2*B1 + c*B1 -D*w*B2- A == 0;
eqn2 = 0.75*k*B2^3 + 0.75*k*B2*B1^2 - m*w^2*B2 + c*B2 -D*w*B1 == 0 ;
eqn1 = subs(eqn1, [k,m,c,A,D], [0.2,1,1,1,0.2]);
eqn2 = subs(eqn2, [k,m,c,A,D], [0.2,1,1,1,0.2]);
sol1 = abs(solve(eqn1,B1));
sol2 = abs(solve(eqn2,B2));

채택된 답변

Walter Roberson
Walter Roberson 2017년 12월 12일
[B1sol, B2sol] = solve([eqn1,eqn2],[B1,B2]);
Y = sqrt(B1sol.^2 + B2sol.^2);
fplot(Y)
These involve fifth order polynomials, so there are 5 solutions, and plotting is rather slow.
Unfortunately, the root() operation that is generated symbolically cannot be translated using matlabFunction, so this cannot easily be translated into a numeric function.
  댓글 수: 4
Walter Roberson
Walter Roberson 2017년 12월 13일
w = 0 is a special case . You need to either ignore it by starting to plot from something greater than 0, or you need to handle it before you do the solve()
For the ignore-it route:
W = linspace(realmin,5);
nY = double(subs(Y.',w,W.'));
nY(imag(nY)~=0) = nan;
plot(W, nY)
Otherwise:
[B1sol0, B2sol0] = solve(subs([eqn1,eqn2], w, 0), [B1,B2]);
nY0 = double( sqrt(B1sol0.^2 + B2sol0.^2) );
nY0(imag(nY0)~=0) = nan;
plot(0, nY0, '*');
hold on
and then do the above "ignore-it" code.
There is only a single real root at w = 0
Jen Cong Wong
Jen Cong Wong 2017년 12월 14일
This works! Thank Walter!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by