I can't figure out why am not getting a plot on my code
1 次查看(过去 30 天)
显示 更早的评论
Write a MATLAB code for plot original and transformation function of
function y=ga(t);
y = -2*(t<=-1)+2*t.*(-1<t&t<=1)+(3-t.^2).*(1<t&t<=3)-6*(t>3);
figure;
tmin=-3;tmax=8;N=100;
dt=(tmax-tmin)/N; t=tmin+dt*[0:N]';
g0=ga(t);g1=-3*ga(4-t);
subplot(2,1,1);p=plot(t,g0,'k');set(p,'LineWidth',2);grid;
ylabel('g(t)');
title('(a)-g(t)=-2,t<-1,2t,-13')
subplot(2,1,2);p=plot(t,g1,'k');set(p,'LineWidth',2);grid;
xlabel('t');ylabel('-3g(4-t');
0 个评论
回答(1 个)
Chunru
2022-10-25
If you put the script and local function ga in the same file, then local functions should be placed at the end of the files as shown below. You can also put the local function in a separate file,
figure;
tmin=-3;tmax=8;N=100;
dt=(tmax-tmin)/N; t=tmin+dt*[0:N]';
g0=ga(t);g1=-3*ga(4-t);
subplot(2,1,1);p=plot(t,g0,'k');set(p,'LineWidth',2);grid;
ylabel('g(t)');
title('(a)-g(t)=-2,t<-1,2t,-13')
subplot(2,1,2);p=plot(t,g1,'k');set(p,'LineWidth',2);grid;
xlabel('t');ylabel('-3g(4-t');
function y=ga(t);
y = -2*(t<=-1)+2*t.*(-1<t&t<=1)+(3-t.^2).*(1<t&t<=3)-6*(t>3);
end
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!