Hello I am stuck with problem 5 I have no idea how to do it

Hello,

I am stuck with problem 5. I have no idea how to do it.

The general solution to the differential dy/dx = x^2 - 2x is y(x) = x^3/3 - x^2 + C with y(0) = C. The goal of this exercise is to write a function file to plot the solutions to the differential equation in the interval 0 lessthanorequalto x lessthanorequalto 5, with initial conditions y(0) = -2, 0, 2. The function file should have the structure function + function (similarly to the M-file myplot i.m Example 3, page 5). The function that defines y(x) must be included in the same file (note that the function defining y(x) will have two input arguments: x and C). Your M-file should have the following structure (fill in all the ?? with the appropriate commands): function ex5 x = ??; % define the vector x in the interval [0, 5] y_1 = f(??); % compute the solution with C = -2 y_2 = f(??); % compute the solution with C = 0 y_3 = f(??); % compute the solution with C = 2 plot (??) % plot the three solutions with different line styles title (??) % add a title legend (??) % add a legend end function y = f(x, c) y = ?? % fill-in with the expression for the general solution end. Plot the graphs in the same window and use different color and/or line-styles for each graph. To plot the graphs in the same window you can use the command hold on or use the plot command similarly to Exercise 4. Add the title \"Solutions to dy/dx = x^2 - 2x\'. Add a legend on the top left corner of the plot with the list of C values used for each graph. (Type help plot for a list of the different line-styles, and help legend for help on how to add a legend.) Include both the M-file and the plot in your report.

Solution

eqn1 = \'Dy =x^2-2*x\';
y = dsolve(eqn1,\'y(0)=c\',\'x\');


%% this is the code for solving the equation
%%use this equation 3 times for c=-2,0,2 and u will get 3 solutions
%% change the boundary condition in my example y(0)=c;
%% and for ur example c is -2,0,2 this will give u 3 solution abd u can plot them

Hello, I am stuck with problem 5. I have no idea how to do it. The general solution to the differential dy/dx = x^2 - 2x is y(x) = x^3/3 - x^2 + C with y(0) = C

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site