You are to create a script in Matlab that will estimate the solution for an ordinary differ- ential equation using the RK4 method outlined above. Below is some code to help you get started: %RK4 clearvars %always helpful to have so matlab doesn't remember past things! f = @(t,y) (-2*t*y^2); %define function, e.g. your y' %the initial conditions yo = 1; to = 0; Q_val= 1; %define query point h = .5; %step size iterationN = round ((Q_val-t0)/step); %helpful if your IVP is not at t=0. yi = zeros(iterationN+1, 1); %initalize empty vector for y values ti = zeros(iterationN+1,1); %initialize empty vector for t values %placing IVP into yi and xi vectors yi (1) = y0; ti(1) = to; From here you need to implement a for loop to approximate the solution.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Using Matlab

Suppose we have the initial value problem (IVP):
y = f(t,y); y(to) = Yo
y is an unknown function
where y is the time derivative of the function y, i.e. y =
of time t, which we would like to approximate; we are told that y, the rate at which y
changes, is a function of t and of y itself. At the initial time to the corresponding y value
is yo. The function f and the data to, yo are given.
We want to 'step' through the function to find a numerical approximation at some time,
t. Choose a step size, h, such that h> 0 and define:
for n = 0, 1, 2, 3,..., using:
Yn+1 = Yn +(k₁ + 2k₂ + 2k³+k₁)
$n+1=t+h
k₁= f(tn, yn)
k₂ = f (tn + 1/3, yn + /2k1)
Yn
k3 = f(tn + 1/2, Yn + 1/2k2)
1
k₁ = f(tn+h, Yn + hk3)
Here yn+1 is the RK4 approximation of y(tn+1), and the next value (n+1) is determined by
the present value (yn) plus the weighted average of four increments, where each increment
is the product of the size of the interval, h, and an estimated slope specified by function f
on the right-hand side of the differential equation.
• k₁ is the increment based on the slope at the beginning of the interval, using y.
• k₂ is the increment based on the slope at the midpoint of the interval, using y + 2k₁;
k3 is again the increment based on the slope at the midpoint, but now using y + k₂;
• k₁ is the increment based on the slope at the end of the interval, using y + hk3.
Transcribed Image Text:Suppose we have the initial value problem (IVP): y = f(t,y); y(to) = Yo y is an unknown function where y is the time derivative of the function y, i.e. y = of time t, which we would like to approximate; we are told that y, the rate at which y changes, is a function of t and of y itself. At the initial time to the corresponding y value is yo. The function f and the data to, yo are given. We want to 'step' through the function to find a numerical approximation at some time, t. Choose a step size, h, such that h> 0 and define: for n = 0, 1, 2, 3,..., using: Yn+1 = Yn +(k₁ + 2k₂ + 2k³+k₁) $n+1=t+h k₁= f(tn, yn) k₂ = f (tn + 1/3, yn + /2k1) Yn k3 = f(tn + 1/2, Yn + 1/2k2) 1 k₁ = f(tn+h, Yn + hk3) Here yn+1 is the RK4 approximation of y(tn+1), and the next value (n+1) is determined by the present value (yn) plus the weighted average of four increments, where each increment is the product of the size of the interval, h, and an estimated slope specified by function f on the right-hand side of the differential equation. • k₁ is the increment based on the slope at the beginning of the interval, using y. • k₂ is the increment based on the slope at the midpoint of the interval, using y + 2k₁; k3 is again the increment based on the slope at the midpoint, but now using y + k₂; • k₁ is the increment based on the slope at the end of the interval, using y + hk3.
You are to create a script in Matlab that will estimate the solution for an ordinary differ-
ential equation using the RK4 method outlined above. Below is some code to help you get
started:
%RK4
clearvars %always helpful to have so matlab doesn't remember past things!
f = @(t,y) (-2*t*y^2); %define function, e.g. your y'
%the initial conditions
yo = 1;
to = 0;
Q_val =
h = .5; %step size
iterationN-
round ((Q_val-t0)/step); %helpful if your IVP is not at t=0.
yi = zeros(iterationN+1, 1); %initalize empty vector for y values
ti = zeros(iterationN+1,1); %initialize empty vector for t values
%placing IVP into yi and xi vectors
yi (1)
1; %define query point
yo;
ti(1) - to;
From here you need to implement a for loop to approximate the solution.
Transcribed Image Text:You are to create a script in Matlab that will estimate the solution for an ordinary differ- ential equation using the RK4 method outlined above. Below is some code to help you get started: %RK4 clearvars %always helpful to have so matlab doesn't remember past things! f = @(t,y) (-2*t*y^2); %define function, e.g. your y' %the initial conditions yo = 1; to = 0; Q_val = h = .5; %step size iterationN- round ((Q_val-t0)/step); %helpful if your IVP is not at t=0. yi = zeros(iterationN+1, 1); %initalize empty vector for y values ti = zeros(iterationN+1,1); %initialize empty vector for t values %placing IVP into yi and xi vectors yi (1) 1; %define query point yo; ti(1) - to; From here you need to implement a for loop to approximate the solution.
Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY