Azzera filtri
Azzera filtri

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

1 visualizzazione (ultimi 30 giorni)
John
John il 25 Ott 2022
Risposto: Chunru il 25 Ott 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');

Risposte (1)

Chunru
Chunru il 25 Ott 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

Categorie

Scopri di più su Manage Products in Help Center e File Exchange

Tag

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by