How to solve two simultaneous equations using solve command?

18 views (last 30 days)
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));

Accepted Answer

Walter Roberson
Walter Roberson on 12 Dec 2017
[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 Comments
Walter Roberson
Walter Roberson on 13 Dec 2017
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

Sign in to comment.

More Answers (0)

Categories

Find more on Mathematics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!