matlab解不定方程 2x+2y=xy+7x=-2:6;y=-2:6;[x,y]=meshgrid(x,y);z=2*x+2*y;k=find(z==x*y+7);x(k)',y(k)'运行结果为ans =Empty matrix:1-by-0ans =Empty matrix:1-by-0请问怎么改
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/09 03:24:06
matlab解不定方程 2x+2y=xy+7x=-2:6;y=-2:6;[x,y]=meshgrid(x,y);z=2*x+2*y;k=find(z==x*y+7);x(k)',y(k)'运行结果为ans =Empty matrix:1-by-0ans =Empty matrix:1-by-0请问怎么改
matlab解不定方程 2x+2y=xy+7
x=-2:6;
y=-2:6;
[x,y]=meshgrid(x,y);
z=2*x+2*y;
k=find(z==x*y+7);
x(k)',y(k)'
运行结果为
ans =
Empty matrix:1-by-0
ans =
Empty matrix:1-by-0
请问怎么改
matlab解不定方程 2x+2y=xy+7x=-2:6;y=-2:6;[x,y]=meshgrid(x,y);z=2*x+2*y;k=find(z==x*y+7);x(k)',y(k)'运行结果为ans =Empty matrix:1-by-0ans =Empty matrix:1-by-0请问怎么改
Empty matrix:1-by-0是说明没有寻找到满足你所设定的条件的点,所以用empty matrix表示.
很简单想法是建议把第二个式子x*y+7先算出来然后z==(这里就是具体数字了,用个for循环代入)
clc;clear;
z=zeros(9,9);
x=-2:1:6;
y=-2:1:6;
i=1;
for m=-2:1:6;
for n=-2:1:6;
z(i)=m*n+7;
i=i+1;
end
end
[x,y]=meshgrid(x,y);
z1=2*x+2*y;
k=find(z1==z)
x(k)',y(k)'
另外一个方法是矩阵:
x=-2:6;
y=-2:6;
[x,y]=meshgrid(x,y);
z=2*x+2*y;
k=find(z==x.*y+7);
x(k)',y(k)'
结果是:
k =
15
35
47
67
ans =
-1 1 3 5
ans =
3 5 -1 1
K
% x*y 要用点乘 x.*y
>> x=-2:6;
y=-2:6;
[x,y]=meshgrid(x,y);
z=2*x+2*y;
k=find(z==x.*y+7);
x(k)',y(k)'
ans =
-1 1 3 5
ans =
3 5 -1 1