フィルターのクリア

Empty sym: 0-by-1

14 ビュー (過去 30 日間)
Alvaro
Alvaro 2023 年 10 月 12 日
コメント済み: Walter Roberson 2023 年 10 月 12 日
When I run this code, my answer for A comes out as 'Empty sym: 0-by-1'
clc;clear;format compact;
syms V
P=[0.98 1.97 4.93 9.86 49.36 98.69]; %atm
T=[573 573 573 573 573 573]; %K
R=461.5; %Pa*m3/mol*K
R=convpres(R,'Pa','atm');
R=R*1000; %L*atm/mol*K
GI=(P*V)-(R*T);
A=solve(GI,V)
A = Empty sym: 0-by-1

採用された回答

Torsten
Torsten 2023 年 10 月 12 日
Use
A = double(arrayfun(@(i)solve(GI(i),V),1:numel(P)))
instead of
A = solve(GI,V)
  1 件のコメント
Dyuman Joshi
Dyuman Joshi 2023 年 10 月 12 日
which can be simplified to
out = double(arrayfun(@(x) solve(x,V), GI))

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

その他の回答 (1 件)

Steven Lord
Steven Lord 2023 年 10 月 12 日
Let's look at the equations you're trying to solve.
syms V
P=[0.98 1.97 4.93 9.86 49.36 98.69]; %atm
T=[573 573 573 573 573 573]; %K
R=461.5; %Pa*m3/mol*K
R=convpres(R,'Pa','atm');
R=R*1000; %L*atm/mol*K
GI=(P*V)-(R*T)
GI = 
The first element of GI has a solution, as does the second element of GI. Is the solution for those two elements exactly the same? To ask that question another way, is there a value of V that satisfies all the elements in GI simultaneously?
A1=solve(GI(1), V)
A1 = 
A2 = solve(GI(2), V)
A2 = 
isAlways(A1 == A2)
ans = logical
0
No, there isn't. So your original solve call that's looking for that one value of V that satisfies all the elements in GI simultaneously is correct to return an empty sym.
Now if you wanted a vector of values of V that satisfy each corresponding element in GI, that's possible to compute.
A = zeros(size(GI), 'sym');
for whichTerm = 1:numel(GI)
A(whichTerm) = solve(GI(whichTerm), V);
end
A
A = 
Do they satisfy their equations?
result = zeros(size(GI), 'sym');
for whichEquation = 1:numel(GI)
result(whichEquation) = subs(GI(whichEquation), V, A(whichEquation));
end
result
result = 
Yes. Are they close to the same value?
vpa(A, 5)
ans = 
Nope. Not even same order of magnitude.
  1 件のコメント
Walter Roberson
Walter Roberson 2023 年 10 月 12 日
This is an important point: solve is always looking for simultaneous solution of all the inputs. It is designed for simultaneous equation solving, and does not have any option for solving each equation individually.

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

カテゴリ

Help Center および File ExchangeNumber Theory についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by