Q1. Modify The MATLAB Code For Jacobi's Iterative ...
Q1. Modify The MATLAB Code For Jacobi's Iterative ...
home / study / math / advanced math / advanced math questions and answers / q1. modify the matlab...
Find solutions for your homework
Q1. Modify the MATLAB code for Jacobi’s iterative scheme (provided and explained in recorded lectures) to
be used for Gauss Seidel iterative formula. Illustrate this with an example.
Q2. Write a MATLAB program to construct and evaluate Lagrange interpolating polynomial for n+1 data
points. Illustrate this with an example.
Expert Answer
Anonymous
answered this
A(:,n+1) =[] ;
for i = 1:n
fprintf('enter (%d)th element :',i)
x(i) = input('') ;
end
normVal=Inf;
while normVal>tol
x_old=x;
for i=1:n
sigma=0;
for j=1:i-1
sigma=sigma+A(i,j)*x(j);
end
for j=i+1:n
sigma=sigma+A(i,j)*x_old(j);
end
x(i)=(1/A(i,i))*(b(i)-sigma);
end
itr=itr+1;
normVal=norm(x_old-x);
end
disp('The solution vector found by Gauss-Seidel iteration becomes :') ;
x
>>
x = [ 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 ] ;
y = [ 0 0.24746646 0.88137359 1.55015796 2.09471255 2.53206806 2.89344399 3.20033494 3.46671104
3.70191108 3.9124227 ] ;
x_test = linspace(0,5,100) ;
y_lagrange = [] ;
n = length(x) ;
N = length(x_test) ;
for i = 1:N
y_lagrange(i) = 0 ;
for j = 1:n
P = y(j) ;
for k = 1:n
if (j ~= k)
P = P * (x_test(i) - x(k))/(x(j)-x(k)) ;
end
end
y_lagrange(i) = y_lagrange(i) + P ;
end
end
y_spline = spline(x,y,x_test) ;
err_lagrange = y - interp1(x,y,x) ;
err_spline = y - spline(x,y,x) ;
subplot(2,1,1) ;
scatter(x , y ,"*","b") ;
hold on ;
subplot(2,1,2) ;
scatter(x , y ,"*","b") ;
hold on ;
>>
0 Comments
0
Up next for you in Advanced Math
See answer
COMPANY
LEGAL & POLICIES
CHEGG NETWORK
CUSTOMER SERVICE