Solve initial value problems

3 views (last 30 days)
Jyan
Jyan on 14 Dec 2014
Commented: Jyan on 14 Dec 2014
I’m supposed to write a function with the name ”min_ode” and call it by ”[t,U]=min ode(f,I,ua,h)” This should solve initial value problems. f is the function, I is the interval [a b], ua is a given number such as u(a)=ua and h is the length of steps. In this case h=0.1 and h=0.001. It should return t and U that is two vectors.
Ex: [t,U]=min ode(@fun,[1 4],2,1e-3)
I want to use ”min_ode” to solve these two problems
1)u(t) = t2, t ∈ [1,3], u(1) = 1.
2)u(t) = tu(t), t ∈ [0,3], u(0) = 1.
These problem should be written as a function file such as ”function y=fun(t,u)”
I’ve made two scripts one called ”min_ode” and one called ”fun”
In the ”min_ode” i wrote:
function [t,U]=min_ode(f,I,ua,h)
I=[0 3];
f=@(t,U)(t.^2);
u(1)=ua;
h=0.01;
end
and in the ”fun” i wrote:
function y=fun(t,U)
f=t.^2;
end
But this is obviously wrong and I’ve tried several times but have not managed to solve it. I would really appreciate if someone would help me

Answers (0)

Community Treasure Hunt

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

Start Hunting!