Borrar filtros
Borrar filtros

Function within a function, Heun's method, system of ODE's

1 visualización (últimos 30 días)
Ollie
Ollie el 12 de Oct. de 2015
Editada: Ollie el 12 de Oct. de 2015
I'm trying to solve the following problem:
This is the Heun's method function file I have set up:
function [t,Y] = myHeun(fNameode, t1, t2, h)
n = (t2-t1)/h;
t = t1:h:t2;
Y=zeros(2,n+1);
y0 = [0.1;0.1];
Y(:,1)=y0;
for I=1:n
k1 = fNameode(t(I),Y(:,I));
k2 = fNameode(t(I)+h,Y(:,I)+h.*k1(:,1));
Y(:,I+1)= Y(:,I)+0.5*h*(k1+k2);
end
My problem comes when I try to program the original function. I have so far tried this:
function z = eqn(y)
y(1) = 0.1;
y(2) = 0.1;
z = [y(1) + 2*sin(3*y(2)),y(1) - 2*y(2)];
end
I seem to have done this second file incorrectly as I am getting error messages when running the Heun's method function my calling on this second function. My question is, how to I program this function correctly and how do I use it in the Heun's method function?
Thanks.

Respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by