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...
Please use python and run in IDLE Question 1 Write functions that do the following: i)...
Please use python and run in IDLE Question 1 Write functions that do the following: i) A function that takes 2 arguments and adds them. The result returned is the sum of the parameters. ii) A function that takes 2 arguments and returns the difference, iii) A function that calls both functions in i) and ii) and prints the product of the values returned by both. Question 2 Write functions: i) One that prompts a user for 2 numbers. ii)...
Write a program with the aim of performing an audiometry test at MATLAB. The program should...
Write a program with the aim of performing an audiometry test at MATLAB. The program should be as interactive as possible. For example, at first, which ear is to be tested should be chosen so that the sound is only given to that channel of the ear. In addition, whether the test frequency increases automatically or manually should be asked as a parameter. The frequencies of the person being tested should be entered by the user as well as whether...
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.
Matlab code problems I have to write a code using functions to find out if a...
Matlab code problems I have to write a code using functions to find out if a year is a leap year. I'm on the write track i feel like but I keep getting an error message and matlab isnt helping to troubleshoot. The issue is on line 30. Here is my code: function project_7_mfp() %   PROJECT_7_ABC   project_7_abc() creates a function that prompts the user %   enter a year after 1582 It then determines if it is a leap year %...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT