Question
I am trying to write a Matlab code to solve a Backwards Euler method and my code is wrong below...can someone make a quick adjustment
I am trying to write a Matlab code to solve a Backwards Euler method and my code is wrong below...can someone make a quick adjustment for it to calculate correctly? I think there is something wrong with the way I solved the Euler formula.
function [t1,v1] = eulerb(a1,b1,n1,u01)
%pde class program to run forward eulers method
%
%
%sample run of the program
%initial values
%a1=0;
%b1=2;
%n1=10;
%[t1,v1] = eulerf(a1,b1,n1,u01)
%compute step size
h1=(b1-a1)1;
u01=1.4;
t1(1)=0;
v1(1)=u01;
%start the loop to update time and compute values
for i = 1:n1
t1(i+1)=a1+(i+1)*h1; %update time value
v1(i+1)=(v1(i)+h1*(sin(t1(i))/(1+h1))); %update approximate values
end
%disp('time values')
%disp(t1)
%disp('approx solution')
%disp(v1)
disp(' times sol values')
results=[t1' v1'];
disp(results)
plot(t1,v1)
grid;shg
end
Task one: determine approximate solutions of the IVP u'(t)=sin(t)u(t), u(0)=1.4, te[0,10]. You will implement the Euler methods derived from the forward and backward difference schemes for 10 time steps, Nt=h=1. Write Matlab codes for the forward difference (forward Euler method) and backward difference (backward Euler method). Provide copies of the codes and output. Copy and paste the code and associated output in the form of a table, for each method, into a word processed document, or print them off to scan with the rest of the homework. The job for both codes is to have them working and producing the output as was done in class (lecture video.) The output table should have the discrete time values in column one and the approximate solution associated with each time step in column two. For this task use n=10 Euler steps. Due Jan. 27. Task one: determine approximate solutions of the IVP u'(t)=sin(t)u(t), u(0)=1.4, te[0,10]. You will implement the Euler methods derived from the forward and backward difference schemes for 10 time steps, Nt=h=1. Write Matlab codes for the forward difference (forward Euler method) and backward difference (backward Euler method). Provide copies of the codes and output. Copy and paste the code and associated output in the form of a table, for each method, into a word processed document, or print them off to scan with the rest of the homework. The job for both codes is to have them working and producing the output as was done in class (lecture video.) The output table should have the discrete time values in column one and the approximate solution associated with each time step in column two. For this task use n=10 Euler steps. Due Jan. 27Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started