Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can anyone help me with a code for solving a differential equation using Euler\'

ID: 3551211 • Letter: C

Question

Can anyone help me with a code for solving a differential equation using Euler's method in Matlab?

I went on a couple of websites but none seemed to help. I have part one, done, I just need help on the second part (boxed in red).


Consider the following initial value problem 2yy'= (y2 + 1)(t + 1), y(0) = 1 Solve the initial value problem and write y(x) explicitly. Use Euler's Method to obtain approximate values of the solution at x = 0.4, 0.8,1.2,1.6, and 2. and compare your numerical solutions with the exact solution found in (1):

Explanation / Answer

%y' = 0.5*(y+1/y)(t+1)

k=2;

u(1)=1;

%case1 h=0.2

t=0;

h=0.2;


for i=1:10

t=t+h;

u(k) = u(k-1)+ h * (0.5*(u(k-1)+1/u(k-1))*(t+1));

k=k+1;

end

x=sprintf('at x=0.4,%f at x=0.8, %f at x=1.2, %f at x=1.6, %f at x=2, %f ',u(2),u(4),u(6),u(8),u(10));

disp(x);


k=2;

u(1)=1;

%case1 h=0.2

t=0;

h=0.2;


h=0.1;


for i=1:20

t=t+h;

u(k) = u(k-1)+ h * (0.5*(u(k-1)+1/u(k-1))*(t+1));

k=k+1;

end

x=sprintf('at x=0.4,%f at x=0.8, %f at x=1.2, %f at x=1.6, %f at x=2, %f ',u(4),u(8),u(12),u(16),u(20));

disp(x);

k=2;

u(1)=1;

%case1 h=0.2

t=0;

h=0.2;


h=0.05;


for i=1:40

t=t+h;

u(k) = u(k-1)+ h * (0.5*(u(k-1)+1/u(k-1))*(t+1));

k=k+1;

end

x=sprintf('at x=0.4,%f at x=0.8, %f at x=1.2, %f at x=1.6, %f at x=2, %f ',u(8),u(16),u(24),u(32),u(40));

disp(x);

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote