Azzera filtri
Azzera filtri

Matlab plot is not correct

1 visualizzazione (ultimi 30 giorni)
주선 문
주선 문 il 25 Ago 2022
Risposto: Chunru il 25 Ago 2022
clc,clear;close all;
f = @(t,y,s) (0.0012*((1-y)/(1.66*10^(6)))+s-0.0012*0.02*y); %y=Nddotexi,vmed=0.02,fdot=3*10^(-18),r=0.0012,k=Nsurv
a = 0; %input('initial ponit, a: ');
b = 100; %input('end point, b: ');
n = 10; %input('intervals, n: ');
alpha = 0; %input('initial condition, alpha: ');
h = (b-a)/n;
t=[a zeros(1,n+1)];
y=[alpha zeros(1,n+1)];
s=[0 zeros(1,n+1)];
for i = 1:n+1
t(i+1)=t(i)+h;
yprime=y(i)+h*f(t(i),y(i),s(i)); %slope
y(i+1)=y(i)+h*f(t(i+1),yprime,s(i+1));
fprintf('%.4f %.4f\n', t(i), y(i));
figure(1)
plot(t(i),y(i),'r-o');
xlabel('t values'); ylabel('y values');
grid on; hold on;
legend('y')
end
Plot dont consist line
How can i fix it?

Risposta accettata

Chunru
Chunru il 25 Ago 2022
f = @(t,y,s) (0.0012*((1-y)/(1.66*10^(6)))+s-0.0012*0.02*y); %y=Nddotexi,vmed=0.02,fdot=3*10^(-18),r=0.0012,k=Nsurv
a = 0; %input('initial ponit, a: ');
b = 100; %input('end point, b: ');
n = 10; %input('intervals, n: ');
alpha = 0; %input('initial condition, alpha: ');
h = (b-a)/n;
t=[a zeros(1,n+1)];
y=[alpha zeros(1,n+1)];
s=[0 zeros(1,n+1)];
for i = 1:n+1
t(i+1)=t(i)+h;
yprime=y(i)+h*f(t(i),y(i),s(i)); %slope
y(i+1)=y(i)+h*f(t(i+1),yprime,s(i+1));
fprintf('%.4f %.4f\n', t(i), y(i));
end
0.0000 0.0000 10.0000 0.0000 20.0000 0.0000 30.0000 0.0000 40.0000 0.0000 50.0000 0.0000 60.0000 0.0000 70.0000 0.0000 80.0000 0.0000 90.0000 0.0000 100.0000 0.0000
figure(1)
plot(t,y,'r-o');
xlabel('t values'); ylabel('y values');
grid on;
legend('y')

Più risposte (0)

Categorie

Scopri di più su Develop Apps Using App Designer in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by