solve関数で簡単な数式を解く方法

4 views (last 30 days)
s
s on 28 Sep 2021
Commented: s on 28 Sep 2021
solve関数を使って
2a + 3b = 0
という方程式をa/bについて解きたいです。
つまり
a/b = -(3/2)
の形にしたいです。
以下が、matlab コードです。
clear; clc; close all;
syms a b
assume(a ~= 0)
assume(b ~= 0)
eqn=2*a+3*b==0
ans=solve(eqn,a/b)
これで解くと、ansが空になります。
原因と対処法を教えていただけましたら幸いです。

Accepted Answer

Atsushi Ueno
Atsushi Ueno on 28 Sep 2021
原因:solve関数がシンボリック変数以外の引数を受け付けないから
対処法:solve関数の出力を個別にシンボリック変数で受け取り、後で計算式を解く
clear; clc; close all;
syms a b
assume(a ~= 0)
assume(b ~= 0)
eqn=2*a+3*b==0;
syms a2 b2
[a2, b2] = solve(eqn,a,b)
a2 = 
b2 = 
1
a2/b2
ans = 
  1 Comment
s
s on 28 Sep 2021
solve 関数は引数を一つ一つでしか認識できなかったのですね。大変勉強になりました。ご丁寧にどうもありがとうございます。

Sign in to comment.

More Answers (0)

Categories

Find more on Symbolic Math Toolbox in Help Center and File Exchange

Tags

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!