大佬们,能尽快解答吗,孩子要交了,先做一两道也行
你好同学,代码供参考:
前两道题:
% 第一题 if 语句
a = input('a:');
b = input('b:');
c = input('c:');
x = input('x:');
if(x<3.5 && x>=0.5)
if(x>=0.5&&x<1.5)
y = a*x^2+b*x+c;
elseif(x>=1.5&&x<3.5)
y = a*sin(x)^c*b+x;
elseif(x>=3.5&&x<5.5)
y = log(abs(b*c/x));
end
fprintf('y的值为%f\n', y);
else
fprintf('wrong input\n')
end
% 1 switch 语句
a = input('a:');
b = input('b:');
c = input('c:');
x = input('x:');
if(x<3.5 && x>=0.5)
n = 1*(x>=0.5&x<1.5) + 2*(x>=1.5&x<3.5) + 3*(x>=3.5&x<5.5);
switch n
case 1
y = a*x^2+b*x+c;
case 2
y = a*sin(x)^c*b+x;
case 3
y = log(abs(b*c/x));
end
fprintf('y的值为%f\n', y);
else
fprintf('wrong input\n')
end
% 第二题
[x1,x2] = meshgrid(-2:0.1:2);
p = 0.5457*exp(-0.75*x2.^2-3.75*x1.^2-1.5*x1).*(x1+x2>1)+...
0.7575*exp(-x2.^2-6*x1.^2).*((x1+x2)>-1&(x1+x2)<=1)+...
0.5457*exp(-0.75*x2.^2-3.75*x1.^2+1.5*x1).*(x1+x2<=-1);
surf(x1,x2,p);colormap(jet)
第二题效果图
有帮助望采纳哟谢谢啦(づ ̄3 ̄)づ╭❤~
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!