Write a short MATLAB script to implement the Euler method of part (b). Include i
ID: 3582011 • Letter: W
Question
Write a short MATLAB script to implement the Euler method of part (b). Include in this script lines of code to take into account the initial-value and boundary conditions. For the initial condition just let f_i denote the value of the function fx) at a node i. Let h = 1, D = 1, and set up a spatial finite difference grid with delta z = 0.25, starting with a labeled node i = 0 at z = 0 (i.e. i = 0, 1, 2, 3, 4). Let the initial condition be given by C_A(z, 0) = f(z) = cos(pi/2 z) (i.e. for 0 lessthanorequalto z lessthanorequalto 1). Choose a time step delta t = 0.01. Does this satisfy the stability criterion? Evaluate the nodal values using the Euler method of part (c) for the first time step (for n = 2, i.e. t = delta t), using a calculator. Consider a one-dimensional insulated bar with fixed temperatures at the boundaries as shown in Fig. 1. The steady-state temperature distribution along the bar is governed by d^2T/dx^2 = 0 Let i denote the x nodal discretization index starting with i = 0 at x = 0 and let delta x denote the discretization increment. Write a central finite difference approximation for Eq. Error! Reference source not found. at an arbitrary interior node i Set up a finite difference grid with delta x = 0.25 and with nodes labeled I = 0, 1, 2, 3 and 4 (i.e. i = 0 and 4 are boundary nodes). Write the central finite difference approximation for this equation at each interior node separately, i.e. for nodes i = 1, 2, and 3. Rewrite the nodal equations in a matrix form Ax = b that can be solved for the nodal values Write a short MATLAB script that solves the discretized nodal equations.Explanation / Answer
Answer:
This is a Matlab programme to solve the differential equations numerically using the Euler's Method.
Programme:
%function a=a(n,a0,a1,b0)
function b=b(n,a0,a1,b0)
h=(a1-a0)/n;
a(1)=a0;
b(1)=b0;
for i=1:n
a(i+1)=a(i)+h;
b(i+1)=b(i)+h*ex(a(i),b(i));
end;
V=[a',b']
plot(a,b)
title('hello')
Explanation:
1.We have to save the above program in a filename.m-file. we call it as euler.m.
2. %x is a function of a and b is the first derivative x'(a)
function b=b(a,x)
b=(a^2-x^2)*sin (x);
On matlab prompt, write euler(n,a0,a1,b0) and return, where n is the number of a-values.
a0 and a1 are the left and right end points. b(a0)=b0 is the initial condition.
Now we will get the answer, also we get the graph.
This is (c) solution for the given post.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.