How do I print one variable from solve() ?

20 ビュー (過去 30 日間)
Jesús Ocegueda
Jesús Ocegueda 2022 年 1 月 31 日
コメント済み: Jesús Ocegueda 2022 年 1 月 31 日
Hello,
I'm trying to print the variable's values obtained after using solve() function. Here is a portion of my code and what I intend to do:
primereq = 18 * A - 8 * B == 0;
segundaeq = -1 * A - 18 * B == 5;
cofval = solve([primereq,segundaeq],[A,B]);
A == cofval.A;
B = cofval.B;
fprintf('El valor de A es %d y el valor de B es %d',A,B);
What would be the correct way to stract the values of the variables A and B from cofval while I use fprintf function?
Thank you for your attention!

採用された回答

Yongjian Feng
Yongjian Feng 2022 年 1 月 31 日
編集済み: Yongjian Feng 2022 年 1 月 31 日
Just do
disp(A);
disp(B);
Or a complete script:
syms A
syms B
primereq = 18 * A - 8 * B == 0;
segundaeq = -1 * A - 18 * B == 5;
cofval = solve([primereq,segundaeq],[A,B]);
fprintf('El valor de A es %f y el valor de B es %f',cofval.A,cofval.B);
  3 件のコメント
Yongjian Feng
Yongjian Feng 2022 年 1 月 31 日
Accept the anwer please if it works.
Jesús Ocegueda
Jesús Ocegueda 2022 年 1 月 31 日
Thank you for the heads up!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeConversion Between Symbolic and Numeric についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by