Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
Ollie
Ollie am 12 Okt. 2015
Bearbeitet: Ollie am 12 Okt. 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.

Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by