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

This is a sample MATLAB code that calculates but with different conditions (So i

ID: 3168390 • Letter: T

Question

This is a sample MATLAB code that calculates but with different conditions (So it doesnt apply to this particular question).

clc;
clear all;
n=8;
m=40;
a=0; % lower limt for x
b=4; %upper limt for x
c=0;% lower limt for t
d=1; % upper limt for t
h=(b-a)/n; % step size for x
k=(d-c)/m; % step size for t

% initial condidtion x=0 to 2
for i=1:n/2+1;
u0(i)=1;
end

% initial condidtion x=2 to 4

% 1.0000


for i=n/2+1:n+1
u0(i)=0;
end
lamd=(k/h^2)
t=0;
while(t<1)
t=t+k
u(1)=1;
u(n+1)=0;
for i=2:n
u(i)=u0(i+1)*lamd+(1-2*lamd)*u0(i)+u0(i-1)*lamd;
end
for i=1:n+1
u0(i)=u(i);
end
  
  
end

2.-7 points ZIllEngMath6 16.2.001 My Notes Ask Your Teacher Use a computer as a computational aid Use the difference equation Uiji 1-Auh ' 1'jt (1-22)Ug + 1,j to approximate the solution of the boundary-value problem ax at u(0, t) = 0, u(6, t) =0,0 t 1 Use n = 8 and m = 40, (Give the approximations obtained for t-1. Round your answers to four decimal places.) u(0.75, 1) u(2.25, 1) u(3.00, 1) u(3.75, 1) u(4.50, 1) u(5.25, 1) eBook Submit Answer Save Progress Practice Another Version Submit AssignmentSave Assignment Progress

Explanation / Answer

clc;
clear all
n=8; % number of points in x
m=40; % number of points in t
a=0; %lower limt of x
b=6; %upper limit of x
c=0; %lower limt of t
d=1 ;% upper limt of t
dx=(b-a)/n; %step length of x
dt=(d-c)/m; %step length of t
x=a:dx:b;

% initial conditon ( from i =1 t0 n/2+1 means 1 to 3)
for i=2:n/2+1
u0(i)=1;
end

% initial conditon ( from i =n/2+1 t0 n/2+1 means 4 to 6)
for i=n/2+2:n+1
u0(i)=0;
end

t=c;
r=dt/dx^2; % (lamda )
while (t<d)
t=t+dt; % increment of t
u(1)=0; % first boundary condition
u(n+1)=0; % second boundary condition
for i=2:n
u(i)=u0(i+1)*r+u0(i)*(1-2*r)+u(i-1)*r; % Given formula
end
for i=2:n
u0(i)=u(i);
end
end
for i=1:n-1
fprintf('u(%f,1)=%f ',i*dx,u(i+1))
  
end

u(0.750000,1)=0.369262
u(1.500000,1)=0.606204
u(2.250000,1)=0.659625
u(3.000000,1)=0.554866
u(3.750000,1)=0.371588
u(4.500000,1)=0.200051
u(5.250000,1)=0.080930
>>

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