MATLAB Answers

code of Euler's

1 view (last 30 days)
Diana Laura Velazquez Lopez
Commented: Walter Roberson on 25 Nov 2020
function edoeuler_v2(f,t0,tf,p0,h)
t = [t0:h:tf]';
n=length(t);
if t(n)<tf
t(n+1)=tf;
n = n+1;
end
p= p0*ones(n,1);
for i = 1:(n+1)
p(i+1) = p(i) + h*f(t(i),p(i));
end
salida=[t p];
output(salida)
end
And then i got this in the command view
edoeuler_v2(@(p)0.0169*t,0,5,0.03,1)
Error using @(p)0.0169*t
Too many input arguments.
Error in edoeuler_v2 (line 10)
p(i+1) = p(i) + h*f(t(i),p(i));

  0 Comments

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 25 Nov 2020
@(t,p)0.0169*t

  2 Comments

Diana Laura Velazquez Lopez
edoeuler_v2(@(t,p)0.0169*t,0,5,0.03,1)
Attempt to execute SCRIPT edoeuler_v2 as a function:
/MATLAB Drive/edoeuler_v2.m
Walter Roberson
Walter Roberson on 25 Nov 2020
Somehow you changed your file edoeuler_v2 so that it no longer starts with
function edoeuler_v2(f,t0,tf,p0,h)

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!