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 Center および File ExchangeProgramming についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by