Note: I have modified the GEpivot.m and saved it in the file GaussWithOutPivot.m
Copyable code:
%File Name: GEpivot.m
%Define function
function [x,lu,piv] = GEpivot(A,b)
%Find value
[m,n] = size(A);
%Check condition
if m ~= n
error('The matrix is not square.')
%End
end
%Find value
m = length(b);
%Check condition
if m ~= n
error('The matrix and the vector do not match in size.')
%End
end
%Create variable
piv = (1:n)';
%Loop
for k = 1:n-1
%Find value
[col_max index] = max(abs(A(k:n,k)));
%Increase value
index = index + k-1;
%Check condition
if index ~= k
%Swap rows k and index
tempA = A(k,k:n);
%Copy value
A(k,k:n) = A(index,k:n);
%Copy value
A(index,k:n) = tempA;
%Swap b
%Copy value
tempb = b(k);
%Copy value
b(k) = b(index);
%Copy value
b(index) = tempb;
%Swap pivot
%Copy value
temp = piv(k);
%Copy value
piv(k) = piv(index);
%Copy value
piv(index) = temp;
%End
end
%Find value
A(k+1:n,k) = A(k+1:n,k)/A(k,k);
%Loop
for i = k+1:n
%Find value
A(i,k+1:n) = A(i,k+1:n) - A(i,k)*A(k,k+1:n);
%End
end
%Find value
b(k+1:n) = b(k+1:n) - A(k+1:n,k)*b(k);
%End
end
%Create
x = zeros(n,1);
%Set value
x(n) = b(n)/A(n,n);
%Loop
for i = n-1:-1:1
%Find value
x(i)=(b(i)-A(i,i+1:n)*x(i+1:n))/A(i,i);
%End
end
%Set value
lu = A;
%End
end
%File Name: GaussWithOutPivot.m
%Define function
function x = GaussWithOutPivot(A, b)
%Find size
[n, n] = size(A);
%Find size
[n, k] = size(b);
%Create variable
tx = zeros(n,k);
%Loop
for i = 1:n-1
%Find value
tp = -A(i+1:n,i)/A(i,i);
%Find value
A(i+1:n,:) = A(i+1:n,:) + tp*A(i,:);
%Find value
b(i+1:n,:) = b(i+1:n,:) + tp*b(i,:);
%End
end
%Find value
tx(n,:) = b(n,:)/A(n,n);
%Loop
for i = n-1:-1:1
%Find value
tx(i,:) = (b(i,:) - A(i,i+1:n)*tx(i+1:n,:))/A(i,i);
%End
end
%Set value
x = tx;
%End
end
%File Name: MySampleRun.m
%Sample Run
nAry = [2 5 10 20 ];
fprintf("\n************************************\n");
%Print message
fprintf("n\t||xD - xP||\t||xD - xNP||\n");
%Print stars
fprintf("************************************\n");
%Loop
for kk= 1: length(nAry)
%Get current n value
n = nAry (kk);
%Define A
A = zeros(n,n);
%Define b
b = ones(n, 1);
%Loop
for i=1:n
%Loop
for j = 1:n
%Find value
A(i,j) = max(i,j);
%End
end
%End
end
%Find value
xD = inv(A)*b;
%Call function
[xP, lu, piv] = GEpivot(A, b);
%Call function
[xNP] = GaussWithOutPivot(A,b);
%Find norm between xD and xP
err1 = norm(xD - xP, inf);
%Find norm between xD and xNP
err2 = norm(xD - xNP, inf);
%Print value
fprintf("%i\t%f\t%f\n", n, err1, err2);
%End
end
fprintf("************************************\n");
Use matlab Need the matlab code Problem 3: (a) Use Fourier transform to find i(t) in the circuit below if v.( 10e2tu(t). Use MATLAB to solve your problem. (b) Plot the magnitude and phase spectrum of the current I(o). 2Ω 3 20 1 H Submit the solution in word file. The used MATLAB code should be included Due date: last day of classes
I NEED THE MATLAB CODE NOT THE ANALYTICAL SOLUTION !!!! using ZIR and 5.1 Use Matlab to find and plot the total response for the differential equation ZSR approach. (D2 +5D 6)y(t)x() where x(t) e-2t sin( 10t) u(t), and the initial conditions are: yo (0)-1 and уо (0)-2.
I need matlab code of the following problem. 1. Plot the values of electric field around a positive charge in free space in two dimensions..... I need the code asap. please.
they need matlab code please help i need the code i need picture for the graph i need it as soon as possible
MATLAB I need the input code and the output. Thanks. 7. Modify the Euler's method MATLAB code presented in the Learning activity video called Using Euler's Method on Matlab (located in the Blackboard Modue#10:: Nomerical Solution to ODE: part 1) to plot and compare the approximate solution using the modified Euler method, for a step size of 0.1 and 0.01
MATLAB question I need the code exactly as you would write it in MATLAB. thank you 1. Consider a Gaussian solution of the traveling-wave form ψ(z,t)-exp(-a(z-vt)2). The parameter values are a 1, 2. (a) Explain the physical meaning of these parameters (eg. what would happen if we took a = 10 instead?) Determine the direction of propagation of this solution: Is it traweling to the left or to the right? (2pts) (b) Write a Matlab code to plot the Gaussian...
I need a working MATLAB CODE for GAUSS SEIDEL ITERATIVE SCHEME the matlab code must compare with actual value and break if this condition is not met i will dislike think before answering a correct working matlab code must be given or else i will dislike badly
I need the solution for matlab
I need the solution for matlab
This problem needs to be solved using MATLAB! I need help with this homework. I will give 100% rating to the answer that is successfully executed and completed. Please provide screenshots of both the MATLAB code and the plots. Problem 4: sketch the signal g(t) = t2 and find the exponential Fourier series to represent g(t) over the interval [-1,1] (Find Dn' s). Plot Dn for n = -20:20. (use stem function in MATLAB and provide your code as well)...