Question
Please add comments to this Matlab code: a) n=1; m=1; stepSize=0.01; for a= -10:stepSize:10 for b= -10:stepSize:10 y(m, n)=funPlot(a,b); x1(m,n)=a; x2(m,n)=b; n=n+1; end m=m+1; n=1;
Please add comments to this Matlab code:
a)
n=1;
m=1;
stepSize=0.01;
for a= -10:stepSize:10
for b= -10:stepSize:10
y(m, n)=funPlot(a,b);
x1(m,n)=a;
x2(m,n)=b;
n=n+1;
end
m=m+1;
n=1;
end
figure
mesh(x1, x2, y)
xlabel('a')
ylabel('b')
zlabel('y')
function y = funPlot(a,b)
if ((abs(a)>abs(b)) || (abs(a)
y=a*a+b*b;
elseif abs(a)==abs(b)
y=0;
end
end
b)
clc
clear all
close all
n=1;
for k=-10:0.01:10
x(n) = k;
if((x(n)<=-1) || ((x(n)>=0) && (x(n)<1)) || (x(n)>=5))
y(n)=0;
elseif ((x(n)>-1) && (x(n)<0))
y(n)=-2*x(n);
elseif (x(n)>=1) && (x(n)<2)
y(n)=-2+2*x(n);
elseif (x(n)>=2) && (x(n)<4)
y(n)=2;
else y(n)=-6+2*x(n);
end
n=n+1;
end
figure
plot(x,y)
axis([-10 10 -0.1 6])
grid on
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started