Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Matlab question in French. Please check my code and helo with the Picture with the question. i am not able to make it work %
Matlab question in French. Please check my code and helo with the Picture with the question. i am not able to make it work
Function definitions
P @x x; Definition of px
Q @x x; Definition of qx
R @xx; Definition of rx
a ; b ; alpha ; beta ;
Parameters
h;
h;
N roundb a h;
N roundb a h;
x linspacea h b h N;
x linspacea h b h N;
P Px;
Q Qx;
R Rx;
P Px;
Q Qx;
R Rx;
Vrification des tailles
dispTailles de P Q R :;
dispsizeP;
dispsizeQ;
dispsizeR;
dispTailles de P Q R :;
dispsizeP;
dispsizeQ;
dispsizeR;
Compute solutions
y problimiteN P Q R a b alpha, beta;
y problimiteN P Q R a b alpha, beta;
Exact solution
c ; d ;
xexact linspacea b;
yexact c xexact.c dlogxexact log;
Plot
plotxexact, yexact, 'LineWidth', ;
hold on;
plotx y 'LineWidth', ;
plotx y 'LineWidth', ;
legendExact solution', h h ;
xlabelx;
ylabely;
titleApproximations numriques vs Solution exacte';
grid on;
hold off;
Calculation of error
Nbrpt ;
Erreurh zeros Nbrpt;
for ii :Nbrpt
N ii;
hi b aii ;
hvaleursii hi;
xi linspacea hi b hi N;
xiinter xi:end ;
Perr Pxiinter;
Qerr Qxiinter;
Rerr Rxiinter;
yboucle problimiteN Perr, Qerr, Rerr, a b alpha, beta;
yboucle yboucle';
yexactei xiinter.logxiinter log;
erreur absyboucle yexactei;
Erreurhii maxerreur;
end
Plot of the error
figure;
logloghvaleurs, Erreurh 'LineWidth', ;
xlabelh;
ylabelErreur;
titleErreur en fonction de la taille du pas h;
grid on;
function x tridiagonalD L U B
Get the length of the main diagonal
n lengthD;
Construct the sparse tridiagonal matrix A
A spdiagsL D U: n n;
Solve the system Ax B
tic; Start timer
x A B;
toc; End timer and display elapsed time
end
function y problimiteN P Q R a b alpha, beta
Initialize vectors for the tridiagonal system
D zerosN;
L zerosN ;
U zerosN ;
B zerosN;
Fill the vectors based on P Q R and other parameters
for i :N
Di Pi Qi Ri;
Bi a i b i;
if i
Li Pi Qi ;
end
if i N
Ui Pi Qi;
end
end
Solve the tridiagonal system
yinterior tridiagonalD L U B;
Construct the complete solution vector
y alpha; yinterior; beta;
end
it shows lik that :
Classroom License for classroom instructional use only.
aaaaa
Tailles de P Q R :
Tailles de P Q R :
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
Error in aaaaatridiagonal line
A spdiagsL D U: n n;
Error in aaaaaproblimite line
yinterior tridiagonalD L U B;
Error in aaaaa line
y problimiteN P Q R a b alpha, beta;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started