필터 지우기
필터 지우기

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;

채택된 답변

James Tursa
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
Janvier Solaris
Janvier Solaris 2017년 10월 6일
This is similar to the answer above Thank you, I tried both implementations and they worked I fed the workspace A, b, and Xo, then I called the function and it gave me the result Again Thank you

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
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
  댓글 수: 1
Janvier Solaris
Janvier Solaris 2017년 10월 6일
Thank you for your prompt answer; This works. If I understood correctly. Build the function then define it, then feed it the variables and it will compute the results. ?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by