在Matlab中求解2个变量的3个方程

时间:2014-05-13 18:02:53

标签: matlab

希望每个人都做得很好。任何人都可以帮我解决Matlab中涉及2个未知变量的3个方程式吗?

我尝试使用符号工具箱,但它给了我一个空的解决方案。 Matlab代码仅适用于2个方程。对于三个方程,它给了我一个空的解决方案。

下面提到了等式:

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

我想解决thetaphi的上述等式。

1 个答案:

答案 0 :(得分:1)

  

任何人都可以帮助我在Matlab中解决2个变量的3 eq,我尝试了很多使用符号工具箱但它给了我空的解决方案。 Matlab代码仅适用于2个方程。对于三个等式给我空解。

最简单的解释是Matlab告诉你的是正确的:三个方程组的系统没有解决方案。

找出正在发生的事情的一种方法是分别绘制三个方程的解。首先取每个方程并将左侧定义为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);

现在您可以使用ezplot(fun1)绘制隐式函数fun1(x,y)=0的解决方案。解决方案将是(θ,φ)平面中的曲线。如果您同时对fun2fun3执行此操作,则同时解决方案将由所有三个函数的曲线同时相交的位置表示。

我不知道如何在同一轴上堆积三个ezplot图,但我们可以使用contour来完成同样的事情:

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

生成此图表:

Matlab contour plot

我们发现红色,蓝色和绿色曲线(分别对应于fun1(x,y)=0fun2(x,y)=0fun3(x,y)=0的解决方案)不会同时相交。

因此,你的三个方程组没有解决方案。

相关问题