Please use MATLAB function ode23 to solve the equation d2ydx
Please use MATLAB function ode23 to solve the equation d^2y/dx^2 + 0.2 dy/dx + sin x/2 + x - 1 = 0; 0 lessthanorequalto x lessthanorequalto 4; y(0) = 0, dy/dx (0) = 0 Please list the result for x, y and dy/dx. Please plot the curves for x vs. y, and x vs. dy/dx on the same graph and y vs. dy/dx on a separate graph, respectively.
Solution
function f=fun1(x,y)
f=y\"+0.2y\'+sin(x/2)+x-1;
>> [xv1 f1]=ode23(\'fun1\',[0 4],1);
disp(\'Solving y\"+0.2y\'+sin(x/2)+x-1;; y(0)=0; between x=0 and t=4\');
options=odeset(\'RelTol\',1e-2);
[X,Y] = ode23(@yprime1, [0, 4], 3, options);
plot(X,Y);
function dy = yprime1(x,y)
f= y\"+0.2y\'+sin(x/2)+x-1
function odedemo1
disp(\'Solving y\"+0.2y\'+sin(x/2)+x-1=0; y(0)=0; between x=0 and x=4 for p=1, 2, and 3\');
for i=1:3
[X,Y] = ode23(@yprime1, [0, 4], 3, [], i);
figure
plot(X,Y);
plot(X,Y\');
plot(Y,Y\');
end
