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 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Janvier Solaris
el 5 de Oct. de 2017
Editada: James Tursa
el 6 de Oct. de 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 comentarios
Respuesta aceptada
James Tursa
el 5 de Oct. de 2017
Editada: James Tursa
el 6 de Oct. de 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
Más respuestas (1)
Walter Roberson
el 5 de Oct. de 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
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!