Question

In: Computer Science

Write the following MATLAB functions. Run it on an example and test it and confirm that...

Write the following MATLAB functions. Run it on an example and test it and confirm that it gives correct results. Show all results. function x=naivege(a,b) that returns the solution to Ax=b obtained by Gauss Elimination without pivoting

Solutions

Expert Solution

Matlab function

============================================================================================

function x=naivege(a,b)


% Gaussian Elimination method without pivoting
%A=[3 4 6;1 -2 7;2 3 -9];
%b=[1;10;15];

% mat is augmented matrix
mat= [a b];

%find size of matrix
[row,col]=size(mat);

for j=1:row-1
for z=2:row
if mat(j,j)==0
t=mat(j,:);mat(j,:)=mat(z,:);
mat(z,:)=t;
end
end
for i=j+1:row
mat(i,:)=mat(i,:)-mat(j,:)*(mat(i,j)/mat(j,j));
end
end

x=zeros(1,row);
for s=row:-1:1
c=0;
for k=2:row
c=c+mat(s,k)*x(k);
end
x(s)=(mat(s,col)-c)/mat(s,s);
end

end

============================================================================================

Output


Related Solutions

Write two functions (must be titled “sumFW” and “sumFF” respectively) in MATLAB that does the following:...
Write two functions (must be titled “sumFW” and “sumFF” respectively) in MATLAB that does the following: take two integers x and y as lower limit and upper limit, then add and display the sum of all the integers between (including) the lower and upper limits. For sumFW you must use the while loop and for sumFF you must use the for loop
Using the string functions below, write new functions to do the following, and test them in...
Using the string functions below, write new functions to do the following, and test them in your main() function: Determine whether the first or last characters in the string are any of the characters a, b, c, d, or e. Reverse a string Determine whether a string is a palindrome (spelled the same way forward or backward FUNCTIONS REFERENCE: string myString = "hello"; // say we have a string… // … we can call any of the following // string...
Normal distribution and discriminant functions Matlab - Write a procedure to calculate the log discriminant function...
Normal distribution and discriminant functions Matlab - Write a procedure to calculate the log discriminant function for a given multi-variate Gaussian distribution and prior probability.
Use the following information to run a t-Test in excel. Write a paragraph description about the...
Use the following information to run a t-Test in excel. Write a paragraph description about the information you found and the conclusions you can draw Your write up should discuss all aspects of hypothesis testing, what is your null and alternative, what are the means and variances of each group, are we running a one- or two-tailed test, why? What is the test statistic, is it statistically significant? In the American society, birthdays are one of those days that everyone...
Use the following information to run a t-Test in EXCEL. Write a paragraph description about the...
Use the following information to run a t-Test in EXCEL. Write a paragraph description about the information you found and the conclusions you can draw.   "To Breakfast or Not to Breakfast?" by Richard Ayore In the American society, birthdays are one of those days that everyone looks forward to. People of different ages and peer groups gather to mark the 18th, 20th, …, birthdays. During this time, one looks back to see what he or she has achieved for the...
Matlab code for Gauss Siedel with solved example in Matlab
Matlab code for Gauss Siedel with solved example in Matlab
Write a program (MATLAB) which generates exponential random variables, and use it to test the Central...
Write a program (MATLAB) which generates exponential random variables, and use it to test the Central Limit Theorem as follows. For various values of n (say, 5, 10, 20, 50, 100, 1000), generate samples of the random variable Mn = 1/n \tiny \sum Xi where Xi are iid exponential random variables. A very simple method for generating exponential random variables is given on page 196 of the textbook (read that section). Plot the discretized CDF for Mn (an approximation of...
Write and test MatLAB code implementing the mathematical models of the boundary value problem to evaluate...
Write and test MatLAB code implementing the mathematical models of the boundary value problem to evaluate the elastic deflection of the beam based on Euler-Bernoulli and Timoshenko theories with finite difference discretisation (for numerical integration and differentiation). The results must be plotted on a graph with labelled local maxima and minima
Use Matlab to write the following 1. Write code to determine whether a year is a...
Use Matlab to write the following 1. Write code to determine whether a year is a leap year. Use the mod function. The rules for determining leap years in the Gregorian calendar are as follows: All years evenly divisible by 400 are leap years. Years evenly divisible by 100, but not by 400, are not leap years. Years divisible by 4, but not by 100, are leap years. All other years are not leap years. For example, the years 1800,...
Write 2 MATLAB functions. One called exptrig which takes a vector of arbitrary length, x, containing...
Write 2 MATLAB functions. One called exptrig which takes a vector of arbitrary length, x, containing any real numbers, and computes the mathematical function f(x) = 3e^(-x)(cos^2(5x) - sin^2(5x)). The other one will be called trigsum, which takes a vector arbitrary length, x, containing any real numbers, and computes the mathematical function g(x)= ((sin(10x) + cos(10x))/ 2) + 3. Both functions will be computed at each of the values of x, and internally will output these values into a vector,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT