I’ve been working on this code for a week now, but I still keep
getting error messages. Can anyone help? Thanks!
Here is my outside function file:
function f = yprime(t,y)
y(1) = 0.5;
t(1) = 0;
f = y .- t.^2 .+ 1;
endfunction
Here is my first code and error message:
function [t,y] = tryrk4(ydot, a, b, y0, h);
i=1;
t(1) = a;
y(1) = y0;
N = 10;
for i=1:N
k1 = feval(ydot, t(i) , y(i) );
k2 = feval(ydot, t(i)+h/2, y(i)+k1*h/2);
k3 = feval(ydot, t(i)+h/2, y(i)+k2*h/2);
k4 = feval(ydot, t(i)+h , y(i)+k3*h );
i = i+1;
t(i) = a+i*h;
y(i) = y(i-1) + (k1 + 2*k2 + 2*k3 + k4)*h/6;
endfor
for i=1:N
[t,y] = [t(i),y(i)];
endfor
endfunction
octave-3.0.2.exe:4:C:\Program Files\Octave\3.0.2_gcc-4.3.0\bin
> tryrk4(yprime, 0,2,.5,.2)
f = 1.5000
Here’s the error message:
error: octave_base_value::function_value(): wrong type argument
`scalar'
error: evaluating assignment expression near line 18, column 7
error: evaluating for command near line 17, column 1
error: called from `tryrk4' in file `C:\Program Files\Octave
\3.0.2_gcc-4.3.0\bin\tryrk4.m'
Thank you for your help! I'm still pretty new to octave, but I'm
getting there!
Camille