Euler Method on without ODE
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hi everyone,
I'm not very familiar for asking question, but I'm lock right know ...
I juste want to solve an ODE withe Euler Method. I've a second degre equation. This case is not my real one, but it is for training. The real one is a little bit more difficult.
Here is my code:
For the equation (saved as test1):
clc;
clear;
clf;
hold off;
t_max=5;
h=0.05;
n=1;
y(:,1)=[0;1];t(1)=0;
% y1=y(1,1);
% y2=y(2,1);
while t(n)<t_max
y(:,n+1)=y(:,n)+h*test(t,y(:,n));
yb=y;
t(n+1)=t(n)+h;
n=n+1;
end
and my function file (saved as fonction_f.m)
function f=test(t,y)
a=5;c=20;
f=[y(2);-a*abs(y(2)*y(2))-c*y(1)];
end
Matlab is answering me
Undefined function or variable 'test'.
Error in test1 (line 18)
y(:,n+1)=y(:,n)+h*test(t,y(:,n));
I realy don't understand where is the problem. For sure my scripts are not excellent, they could be better. But actually I'm learning by myself without any help ...
Thanks to you for your help
Charles
0 comentarios
Respuestas (1)
James Tursa
el 6 de Abr. de 2016
Editada: James Tursa
el 6 de Abr. de 2016
When calling a function file, MATLAB calls it based on the filename, not the function name listed on the function line in the file. So your function is known to MATLAB as fonction_f, not test, since the name of the file is fonction_f.m. You need to rename that file as test.m. You probably have a yellow squiggly line on test when you look at it in the editor. That is MATLAB telling you about this problem. Hover the cursor over it and you will see the message.
0 comentarios
Ver también
Categorías
Más información sobre Ordinary Differential Equations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!