CHE222 Lab 8 - Tuesday, March 13 Learning Outcomes: After this lab, you should b
ID: 3726559 • Letter: C
Question
CHE222 Lab 8 - Tuesday, March 13 Learning Outcomes: After this lab, you should be able to use Euler's method for numerical integration. Prelab - 2 Points: For the arbitrary function calculates and outputs the value of G for any inputted y value. Your function definition should loolk omething like this: ay =-3y + 30, create a new MATLAB function that dt dt function dy = functionname(y,t) Create a new script that uses your created function to implement Euler's method to approximate the value oty over a time period of 0 to 100 seconds. You may assume yo-0 and you may use At-2. The algorithm for Euler's Method is described below. Euler's method: Given an initial value of yo at time to and an expression for the first derivative *- f(t, y), the value of the variable y after a time interval of At, denoted by y1, can be estimated by: dt Eq. 1 Which can be iteratively evaluated to estimate the value of y at each subsequent time step until a specified time tfinal Algorithm (1) Determine the number of required steps n using n - (2) Starting from i = 0, set yi and ti to their initial values of yo and to (3) Calculate the derivative using the function f (ti,yi) (4) Estimate the value of yit1 at time ti + t using: final LO At 2 (5) Calculate the value of ti+1 using tH-t + t and also update the iterator using 1 = 1 + 1. (6) Ifi is less than or equal to n, repeat steps 3-5. Otherwise, stop.Explanation / Answer
function dy = functionname(y,t)
dy=-3*y+30;
%script for euler
deltaT=2;
t=0:deltaT:100;
y=zeros(1,length(t));
y(1)=0;
for i=2:length(t)
y(i)=y(i-1)+deltaT*(functionname(y(i-1),t(i-1)));
end
%if any doubts, ask in comments