Question: Write a similar Python codsyms h A = [ 1 1 1 1 1 ; - 2 - 1 0 1 2 ; 4 1

Write a similar Python codsyms h
A=[11111;-2-1012;41014;-8-1018;1610116];
b=[002h???200]';
% solve the linear system of equations to obtain the coeffiecients
x=A??b
fdstencil (2,-2:2)
uptrue =-4**sin(2);
sixth_derivative =-64**sin(2);
hvals = logspace (-1,-4,13);
D5u=[];
E5u=[];
E5u_pred =[];
% table headings
disp ('')
disp(' h
D5u
E5u')
for i=1 : length (hvals)
h= hvals(i);
xpts=1+h***(-2:2)';
D5u(i)=fdcoeffF(2,1,xpts)**sin(2**xpts);
rror
E5u(i)= D5u(i)-uptrue;
E5u_pred =-0.0111111**(h???4)** sixth_derivative;
disp (sprintf ('%13.8e
%15.8e
15.8e',
h, D5u(i), E5u(i)))
end
Plot errors
Clf
loglog (hvals,abs (E5u),'-')
hold on
loglog(hvals,abs (E5u_pred),'-')
title('log log plot of errors vs h')
xlabel ('h')
ylabel('Errors (E5u)')
legend('Numerical Error','Predicted Truncation Error','Location', 'North')
hold offe of this matlab code.
clc; clear; close all;
% Problem 2
syms h
A =[11111;-2-1012; 41014; -8-1018; 1610116];
b =[002/h^200]';
% solve the linear system of equations to obtain the coeffiecients
x = A\b
fdstencil(2,-2:2)
uptrue =-4*sin(2);
sixth_derivative =-64*sin(2);
hvals = logspace(-1,-4,13);
D5u =[];
E5u =[];
E5u_pred =[];
% table headings
disp('')
disp(' h D5u E5u')
for i=1:length(hvals)
h = hvals(i);
xpts =1+h*(-2:2)';
D5u(i)= fdcoeffF(2,1,xpts)*sin(2*xpts);
% Error
E5u(i)= D5u(i)-uptrue;
E5u_pred =-0.0111111*(h^4)*sixth_derivative;
disp(sprintf('%13.8e %15.8e %15.8e',
h,D5u(i),E5u(i)))
end
% Plot errors
clf
loglog(hvals,abs(E5u),'o-')
hold on
loglog(hvals,abs(E5u_pred),'-')
title('log log plot of errors vs h')
xlabel('h')
ylabel('Errors (E5u)')
legend('Numerical Error','Predicted Truncation Error','Location','North')
hold off
 Write a similar Python codsyms h A=[11111;-2-1012;41014;-8-1018;1610116]; b=[002h???200]'; % solve the

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!