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

조회 수: 2 (최근 30일)
Ollie
Ollie 2015년 10월 12일
편집: Ollie 2015년 10월 12일
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.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by