System solving using rref

조회 수: 11 (최근 30일)
Abdulaziz Aljaber
Abdulaziz Aljaber 2018년 9월 6일
댓글: Walter Roberson 2018년 9월 6일
Hello,
So I am trying to write a system solving script using rref. Matrix and vector, A and B, are given already. What is needed is solving the 3 equation, also given, and produce an output file that looks like screenshot 1, but instead i get an output of screenshot 2. And I apologize for not including the code into the body, but i have no clue how to do it properly.
Thanks
  댓글 수: 2
madhan ravi
madhan ravi 2018년 9월 6일
just upload your code instead of a screenshot
Abdulaziz Aljaber
Abdulaziz Aljaber 2018년 9월 6일
Just did! didnt know they had a code button that does it for you.

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

답변 (2개)

Abdulaziz Aljaber
Abdulaziz Aljaber 2018년 9월 6일
load ('A');
load ('B');
rref(A);
rref(B);
syms a b c d x y z
Eq1 = 1*x + (-2*y) + 3*z == 7;
Eq2 = 2*x + 1*y + 1*z == 4;
Eq3 = -3*x + 2*y + -2*z == 1;
fprintf('Equation 1 is: 7 %6.4f\n','Equation 2 is: %6.4f\n', 'Equation 3 is:%6.4f\n')
fprintf('The solutions are as follows: %n', x, y, z)
fid=fopen('output data.txt','wt');
fprintf(fid, '%f %f r\n');
fclose(fid);
  댓글 수: 1
Abdulaziz Aljaber
Abdulaziz Aljaber 2018년 9월 6일
this is what i get as a result
Equation 1 is: 7 69.0000
Equation 1 is: 7 113.0000
Equation 1 is: 7 117.0000
Equation 1 is: 7 97.0000
Equation 1 is: 7 116.0000
Equation 1 is: 7 105.0000
Equation 1 is: 7 111.0000
Equation 1 is: 7 110.0000
Equation 1 is: 7 32.0000
Equation 1 is: 7 50.0000
Equation 1 is: 7 32.0000
Equation 1 is: 7 105.0000
Equation 1 is: 7 115.0000
Equation 1 is: 7 58.0000
Equation 1 is: 7 32.0000
Equation 1 is: 7 37.0000
Equation 1 is: 7 54.0000
Equation 1 is: 7 46.0000
Equation 1 is: 7 52.0000
Equation 1 is: 7 102.0000
Equation 1 is: 7 92.0000
Equation 1 is: 7 110.0000
Equation 1 is: 7 69.0000
Equation 1 is: 7 113.0000
Equation 1 is: 7 117.0000
Equation 1 is: 7 97.0000
Equation 1 is: 7 116.0000
Equation 1 is: 7 105.0000
Equation 1 is: 7 111.0000
Equation 1 is: 7 110.0000
Equation 1 is: 7 32.0000
Equation 1 is: 7 51.0000
Equation 1 is: 7 32.0000
Equation 1 is: 7 105.0000
Equation 1 is: 7 115.0000
Equation 1 is: 7 58.0000
Equation 1 is: 7 37.0000
Equation 1 is: 7 54.0000
Equation 1 is: 7 46.0000
Equation 1 is: 7 52.0000
Equation 1 is: 7 102.0000
Equation 1 is: 7 92.0000
Equation 1 is: 7 110.0000
The solutions are as follows: >>

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


Walter Roberson
Walter Roberson 2018년 9월 6일
fprintf('Equation 1 is: %s\nEquation 2 is: %s\nEquation 3 is: %s\n', Eq1, Eq2, Eq3);
fprintf('The solutions are as follows:\n');
Now calculate the solutions and store them in variables X, Y, and Z, then:
fprintf('x = %.4f\ny = %.4f\nz = %.4n\n', X, Y, Z)
I recommend that you do not store the solutions in variables x, y, and z, as that gets confusing against the use of x, y, and z as symbolic variables.
  댓글 수: 2
Abdulaziz Aljaber
Abdulaziz Aljaber 2018년 9월 6일
Okay that is better, but is there a way to let matlab solve it for me? because that is what is asked for.
Walter Roberson
Walter Roberson 2018년 9월 6일
We have no information about relationship A and B have to the rest of the question.
My guess is you want something like
for row = 1 : size(A,1)
fprintf('Equation %d is: %5fx + %5fy + %5fz = %5f\n', A(row,:), B(row));
end
and that you want to use rref() to solve the system
A*[x;y;z] = B
It is easy to do, taking only a few characters, but figuring out how is an important part of the homework.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by