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 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
James Tursa
2017-10-5
编辑:James Tursa
2017-10-6
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
更多回答(1 个)
Walter Roberson
2017-10-5
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!