Hi, I have a huge problem. I have to write a script that solve differential equation like this
2000y"=98(1+y')^2{t(t1)+2}
using AdamsBashforthMoulton method and then compare results using ode45. I wrote a function
>function dy = belka(t,y)
>% funkcja w której zapisali?my równanie różniczkowe
>dy=zeros(2,1) ;
>dy(1)=y(2);
>dy(2)=(9.8*10/2000)*(1+y(2))^2*{t.*(t1)+2};
>end
And I have a function
>function [ t, y ] = ode_abm( f, tspan, y0, N, KC, varargin )
>%UNTITLED Summary of this function goes here
>% Detailed explanation goes here
>if nargin<5, KC=1; end
>if nargin<4  N<=0. N=100; end
>y0=y0(:)';
>h=(tspan(2)tspan(1))/N;
>tspan0=tspan(1)+[0 3]*h;
>[t, y]=rk4(f, tspan0, y0, 3, varargin{:});
>t=[t(1:3)' t(4):h:tspan(2)]';
>for k=1:4, F(k,:)=feval(f, t(k), y(k,:), varargin{:}); end
>p=y(4,:); c=y(4,:); KC22=KC*251/270; KC12=KC*19/270;
>h24=h/24; h241=h24*[1 5 19 9]; h249=h24*[9 37 59 55];
>for k=4:N
> p1=y(k,:)+h249*F;
> m1=pk1+KC22*(cp);
> c1=y(k,:)+h241*[F(2:4,:); feval(f,t(k+1), m1, varargin{:})];
> y(k+1,:)=c1KC12*(c1p1);
> p=p1; c=c1;
> F=[F(2:4,:);feval(f,t(k+1),y(k+1,:), varargin{:})];
>end
>end
It has inside function rk4, so
function [ t, y ] = rk4( f, tspan, y0, N, varargin )
%UNTITLED8 Summary of this function goes here
% Detailed explanation goes here
if nargin<4  N<=0, N=100; end
if nargin<3, y0=0; end
y(1,:)=y0(:)';
h=(tspan(2)tspan(1))/N; t=tspan(1)+[0;N]'*h;
for k=1:N
f1=h.*feval(f,t(k),y(k,:),varargin{:}); f1=f1(:)';
f2=h.*feval(f,t(k)+h/2,y(k,:)+f1/2,varargin{:}); f2 = f2(:)';
f3=h.*feval(f,t(k)+h/2,y(k,:)+f2/2,varargin{:}); f3 = f3(:)';
f4=h.*feval(f,t(k)+h,y(k,:)+f3,varargin{:}); f4 = f4(:)';
y(k+1,:)=y(k,:)+(f1+2.*(f2+f3)+f4)/6;
end
But i doesn't work. Matlab says
>> [t, y]=ode_abm(@belka, [0 2], [0 0], 100, 1)
??? Undefined function or method 'mtimes' for input arguments of
type 'cell'.
Error in ==> belka at 5
dy(2)=(9.8*10/2000)*(1+y(2))^2*{t.*(t1)+2};
Error in ==> rk4 at 9
f1=h.*feval(f,t(k),y(k,:),varargin{:}); f1=f1(:)';
Error in ==> ode_abm at 9
[t, y]=rk4(f, tspan0, y0, 3, varargin{:});
What is wrong? Could anyone help me? That means a lot for me. I am really bad it Matlab, so please give me simple explanation ;)
