syms y(t);
ode = diff(y,t) == y - t*t + 1; % defining f(t,y)
cond = y(0) == 0.5; % defining the initial condition y(0) = 0.5
ySol(t) = dsolve(ode,cond); % solving ODE given f(t,y) and initial condition. ySol(t) will be a solution.
% PLOTTING
N = 100; % the number of points
t = linspace(0,2,N); % N number of equispaced data points between 0 and 2
plot(y,ySol(t));
title("Solution");
Matlab code for (a).
syms y(t);
ode = diff(y,t) == - (y^3 +y) / ( (3*y^2 + 1) * t); % defining f(t,y)
cond = y(1) == 1; % defining the initial condition y(0) = 0.5
ySol(t) = dsolve(ode,cond); % solving ODE given f(t,y) and initial condition. ySol(t) will be a solution.
% PLOTTING
N = 100; % the number of points
t = linspace(1,2,N); % N number of equispaced data points between 1 and 2
plot(y,ySol(t));
title("Solution");
hold on;
% APPROXIMATE y(2) USING NEWTON'S METHOD
y_2 = 0; % setting initial point
% Newton's method
max_iteration = 100; % maximum iterations for Newton's method
tolerance = 1e-6; % tolerance to quit the method
for i=1:max_iteration
eval = (y_2^3 + y_2 - 1) / (3*y_2^2 + 1);
if abs(eval) < tolerance
break
end
y_2 = y_2 - eval;
end
plot(2,y_2,'o') % plotting the approximate solution on the graph
hold off