100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
APM1513 Assignment 2 solutions 2021 semester 1 R250,00
Add to cart

Other

APM1513 Assignment 2 solutions 2021 semester 1

1 review
 130 views  2 purchases

APM1513 Assignment 2 solutions 2021 semester 1 . Code and output included

Preview 2 out of 10  pages

  • June 3, 2021
  • 10
  • 2021/2022
  • Other
  • Unknown
All documents for this subject (9)

1  review

review-writer-avatar

By: frononselen • 3 year ago

Might as well just look at Chegg. He/she just copied and pasted from there for 99% of the solutions.

avatar-seller
cilliersfrederick
APM1513

Assignment 2




Question 1
give two commands

>rand("state",student_number);

>rand(1)



Run own output and paste your output here



Question 2

function x = gauss_seidel(A,d,x0,tol,Imax)
% gauss_seidel: implements the Jacobi iterative method
% for solving a system of linear equations.
% Input: A = square coefficient matrix (nxn)
% d = right hand side vector (nx1)
% x0 = initial guess (nx1) (default = zeros)
% tol = stop criterion (default = 10^-6)
% Imax = maximum iterations (default = 100)
% Output: Solution vector.
if nargin<5, Imax=100; end
if nargin<4, tol=10^-6; end
[m,n]=size(A);
if m~=n, error('Matrix A must be square'); end
if nargin<3, x=zeros(n,1); else x=x0; end
C=A;
for i=1:n
C(i,i)=0;
end
for i=1:n
C(i,1:n)=C(i,1:n)/A(i,i);
end
b=zeros(1,n);
for i=1:n
b(i)=d(i)/A(i,i);
end
iter=0;
while true
x_old=x;
for i=1:n
x(i)=b(i)-C(i,:)*x;
if x(i)~=0
err(i)=abs((x(i)-x_old(i))/x(i));
end
end
iter=iter+1;

, if iter>=Imax || norm((x-x_old)./x)<tol
fprintf('Total Iterations are: %d\n',iter);
return
end
end
end

clc
clear all
close all
A=[20,-1,1;2,10,-1;1,1,-20];
b=[20;11;-18];
disp('Solution by backslash is');
x=A\b
disp('Solution by gauss siedel');
x=gauss_seidel(A,b,[1;2;3],1e-7,100)
function x = gauss_seidel(A,d,x0,tol,Imax)



Output:

x =


1.0000
1.0000
1.0000




Question 3




clc
clear all
close all
A=[12,-3,4,-2;1,10,-1,-20;1,-1,20,4;1,1,-20,-3];
b=[12;15;-7;-5];
disp('Solution of part a using backslash is');
A\b
disp('Solution of part a using backslash is');
gauss_seidel(A,b,[1;2;3;4],1e-7,100)
function x = gauss_seidel(A,d,x0,tol,Imax)
% gauss_seidel: implements the Jacobi iterative method
% for solving a system of linear equations.
% Input: A = square coefficient matrix (nxn)
% d = right hand side vector (nx1)
% x0 = initial guess (nx1) (default = zeros)
% tol = stop criterion (default = 10^-6)
% Imax = maximum iterations (default = 100)

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through EFT, credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying this summary from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller cilliersfrederick. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy this summary for R250,00. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

53068 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy summaries for 14 years now

Start selling
R250,00  2x  sold
  • (1)
Add to cart
Added