How to solve two simultaneous equations using solve command?

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));

 Akzeptierte Antwort

[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 Kommentare

W = linspace(-5,5);
nY = double(subs(Y.',w,W.'));
nY(imag(nY)~=0) = nan;
plot(W, nY)
Thank you so much. But is it possible to plot from 0 to 5? I changed the linspace value from 0 to 5 and matlab said:
Error using symengine
Division by zero.
Error in sym/subs>mupadsubs (line 140)
G = mupadmex('symobj::fullsubs',F.s,X2,Y2);
Error in sym/subs (line 125)
G = mupadsubs(F,X,Y);
Error in NonlinearStudyWithDamping (line 19)
nY = double(subs(Y.',w,W.'));
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
This works! Thank Walter!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Mathematics finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by