In: Mechanical Engineering
y'=y-x^2 ; y(1)= -4
Write a MATLAB program that makes two plots of the solution to the equation using the following values. Suggest you use nested loops instead of two different loops. Be sure to label your plots.
a. x0 = 1.0, step size h = .2, number of steps n = 20.
b. x0 = 1.0, step size h = .05, number of steps n = 80.
here I solved in Matlab and copy of script and graph attached here below.
I don't think that you need to use any loop so I solved it directly without using any loop and plotted both given condition separately as shown below.
Sorry for your any kind of inconvenience, or If you find any query or need further help just comment below I will guide you surely. Thank you.
********************************** Matlab Script ***************************************
clc
clear all
xspan = [1:0.2:5];
y1 = -4;
[x,y] = ode45(@(x,y) y-x^2, xspan, y1);
subplot(2,1,1);
plot(x,y,'pk')
xlabel('value of x')
ylabel('value of y(x)')
grid on
xspan = [1:0.05:5];
y1 = -4;
[x,y] = ode45(@(x,y) y-x^2, xspan, y1);
subplot(2,1,2);
plot(x,y,'.k')
xlabel('value of x')
ylabel('value of y(x)')
grid on
***************************************************************************************************
Screenshots