function [T,N] = expgrowthEULER(N0,tmax,dt,r);
T=[0:dt:tmax]
N=zeros(length(T),1)
N(1)=N0
for i=2:length(T)
N(i)=N(i-1)+r*N(i-1)*dt
end
end
N0=1
r=0.1
tmax=10
dt=0.1
[T,N]=expgrowthEULER(N0,tmax,dt,r)
plot(T,N)
It says I have an undefined variable 't'.

 Réponse acceptée

madhan ravi
madhan ravi le 5 Déc 2018
Modifié(e) : madhan ravi le 5 Déc 2018
correct usage is as shown below:
N0=1;
r=0.1;
tmax=10;
dt=0.1;
[T,N]=expgrowthEULER(N0,tmax,dt,r) ; %function call
plot(T,N)
function [T,N] = expgrowthEULER(N0,tmax,dt,r) % function definition
T=[0:dt:tmax];
N=zeros(length(T),1);
N(1)=N0;
for i=2:length(T)
N(i)=N(i-1)+r*N(i-1)*dt;
end
end

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by