I am supposed to write a function that takes three inputs: 1) a Coeff matrix A(nxn square mtx), right side vector b, and approximate soln' vector Xo. The function is then supposed to compute the residual vector r.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Janvier Solaris
le 5 Oct 2017
Modifié(e) : James Tursa
le 6 Oct 2017
This is the code I have so far but I believe this is wrong since the function doesn't ask me for any inputs it outputs what I have inputted then I can calculate r...Any help would be greatly appreciated. I am still trying to learn Matlab
basically I want to be able to input a 4x4 mtx, the right hand side vector, the soln vector , then the function calculates the residual vector. it does so without it being a function but I would like to make it a function Thank You
function[] = residv(A, b, x)
A = [1 3 -1; -1 3 4; 5 6 7]
b = [2;3;8]
x = A \ b;
%x = inv(A)*b
r = b - A*x;
0 commentaires
Réponse acceptée
James Tursa
le 5 Oct 2017
Modifié(e) : James Tursa
le 6 Oct 2017
To my reading of the assignment, you are making this task more involved than it really is. The assignment states you are given A, b, and Xo. Then you are to calculate and return the residual r. So your function should look something like this:
function r = residv(A, b, Xo)
r = _______; % <-- you fill this in. an expression involving A, b, and Xo
return
end
Plus de réponses (1)
Walter Roberson
le 5 Oct 2017
You would do the
A = [1 3 -1; -1 3 4; 5 6 7]
b = [2;3;8]
x = A \ b;
outside of the code for the function, and you would invoke the function passing those in, like
A = [1 3 -1; -1 3 4; 5 6 7]
b = [2;3;8]
x = rand(3,1);
residv(A, b, x)
Your function is probably supposed to output r
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!