Ode23 Example
Ode23 Example
y' =
ty 2 y2
, y (0) = 1, t [0, 5]
Step2: Test the function by entering in the command window fun1(1,1). The result should be
Now use MatLab functions ode23 and ode45 to solve the initial value problem numerically and then plot the numerical solutions y, respectively. In the MatLab window, type in the following commands line by line.
>> [tv1 f1]=ode23('fun1',[0 5],1); % Generates a set of points and stores them in vectors tv1 and f1 >> [tv2 f2]=ode45('fun1',[0 5],1); % Generates a set of points and stores them in vectors tv2 and f2 >> plot(tv1,f1,'-.',tv2,f2,'--') % plots two graphs with coordinate sets (tv1,f1) and (tv2,f2) >> title('y''=-ty/sqrt(2-y^2), y(0)=1, t in [0, 5]') % Provide a title to graph >> grid % Provide a grid >> axis([0 5 0 1]) % set the x and y axis limits to (0,5) and (0,1)
Note: Anything you enter after % is considered as comment line. Step 4: Read a particular solution for say t =2, the value of y and report the result.
There are two plots in the same graph, hardly distinguisahble since the results by ode23 and ode45 functions are close to each other.