# I can't figure out why am not getting a plot on my code

1 view (last 30 days)
John on 25 Oct 2022
Answered: Chunru on 25 Oct 2022
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');

Chunru on 25 Oct 2022
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

### Categories

Find more on Language Fundamentals in Help Center and File Exchange

R2022b

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!