简体   繁体   中英

solve 3 equation in Matlab for 2 variables

Hope everyone is doing well. Can anyone help me in solving 3 equations involving 2 unknown variables in Matlab?

I tried using symbolic toolbox but it gives me an empty solution. The Matlab code works for 2 equations only. For three equations it gives me an empty solution.

The equation are mentioned below:

cos^2(2\phi) cos(2\theta + sin(2\phi)cos(2\phi) sin(2\theta)=0    
sin(2\phi)cos(2\phi)cos(2\theta)+sin^2(2\phi)sin(2\theta)=0    
-sin(2\phi)cos(2\theta)+cos(2\phi)sin(2\theta)=0

I want to solve the above equations for theta and phi .

Can anyone help me in solving 3 eq for 2 variables in Matlab, I tried a lot using symbolic tool box but it gives me empty solution. The Matlab code works for 2 equation only. For three equation gives me empty solution.

The simplest explanation is that what Matlab is telling you is correct: there is no solution for the system of three equations.

One way to find out what's happening is to plot the solutions for the three equations individually. First take each equation and define the left side as a function in Matlab:

fun1 = @(phi, theta)  cos(2*phi).^2 .* cos(2*theta)            + sin(2*phi) .* cos(2*phi) .* sin(2*theta);
fun2 = @(phi, theta)  sin(2*phi) .* cos(2*phi) .* cos(2*theta) + sin(2*phi).^2 .* sin(2*theta);
fun3 = @(phi, theta) -sin(2*phi) .* cos(2*theta)               + cos(2*phi) .* sin(2*theta);

Now you can use ezplot(fun1) to plot the solutions to the implicit function fun1(x,y)=0 . The solutions will be curves in the (theta, phi) plane. If you do this for fun2 and fun3 as well, the simultaneous solution will be represented by places where the curves from all three functions simultaneously intersect.

I don't know how to pile up three the three ezplot plots on the same axes, but we can use contour to accomplish the same thing:

x = linspace(-pi/2, pi/2, 180);
y = linspace(-pi/2, pi/2, 180);

[X, Y] = meshgrid(x, y);

contour(X, Y, fun1(X, Y), [0, 0], 'r', 'linewidth', 3);
hold all
contour(X, Y, fun2(X, Y), [0, 0], 'b');
contour(X, Y, fun3(X, Y), [0, 0], 'g');
hold off

legend('f_1(\theta,\phi)=0','f_2(\theta,\phi)=0','f_3(\theta,\phi)=0');
xlabel('\phi');
ylabel('\theta');

Which produces this graph:

Matlab等高线图

We see that there are no points where the red, blue, and green curves (corresponding to solutions of fun1(x,y)=0 , fun2(x,y)=0 , and fun3(x,y)=0 , respectively) simultaneously intersect.

Thus your system of three equations has no solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM