d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Matlab Help Please! > Need Help With The Second Part Of A Prog
Add Reply New Topic New Poll
Member
Posts: 388
Joined: Sep 21 2015
Gold: 220.74
Oct 5 2015 09:06pm
(a) Write a well-commented Matlab function program mysolvecheck with input a number n
that makes a random n × n matrix A and a random vector b, solves the linear system Ax = b,
calculates the magnitude of the residual r = Ax − b, and outputs that number as the error e.

I have this part done on my other computer, I cannot retrieve it right now because I accidentally saved it to my desktop so I dont need this part, but I can't give you what I have currently. Its a pretty easy code.

(b) Write a well-commented Matlab script program that calls mysolvecheck 5 times each for
n = 5, 10, 50, 100, 500, and 1000, records and averages the results, and makes a log-log plot of
the average e vs. n.

This is the part where I am struggling, please offer either some psuedo code or some actual code that can get me going in the right direction!
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Oct 5 2015 09:19pm
what part do you have a problem with?

here's how to call your function:
e5 = mysolvecheck(5)

here's how to average the results:
http://www.mathworks.com/help/matlab/ref/mean.html

here's how to make a log-log plot
http://www.mathworks.com/help/matlab/ref/loglog.html
Member
Posts: 388
Joined: Sep 21 2015
Gold: 220.74
Oct 5 2015 09:24pm
Quote (carteblanche @ Oct 5 2015 10:19pm)
what part do you have a problem with?

here's how to call your function:
e5 = mysolvecheck(5)

here's how to average the results:
[URL=http://www.mathworks.com/help/matlab/ref/mean.html]http://www.mathworks.com/help/matlab/ref/mean.html[/URL]

here's how to make a log-log plot
[URL=http://www.mathworks.com/help/matlab/ref/loglog.html]http://www.mathworks.com/help/matlab/ref/loglog.html[/URL]


Thanks for the info, I'll give all that a try when I can get the first part of my code again tomorrow. I guess I thought I needed some sort of for loop to call mysolvecheck 5 times for each n value, then after that average the result of each n value to get an n by 1 array of the average values which would then need to be averaged again to get one single value to be plotted.

Maybe I'm misinterpreting the problem though

This post was edited by bensfriend2 on Oct 5 2015 09:26pm
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Oct 5 2015 09:43pm
you can set your n values into an array and loop through them if you wish.
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll