Solve equation with multiple values for V

6 ビュー (過去 30 日間)
Alexander Madsen
Alexander Madsen 2021 年 10 月 24 日
コメント済み: Star Strider 2021 年 10 月 25 日
Hi, i'm trying so solve an equation with 19 different values for V and Pv. It's possible when i do it one at a time, but not when I'm trying with a loop.
Vr=12;
Vi=3;
Pr=max(P_test_data4);
Pv=P_test_data4;
V=WS_test_data4;
syms n
for i=0:length(WS_test_data4);
solve((Pr*((V.^n)-(Vi.^n)))/((Vr.^n)-(Vi.^n))==Pv,n)
end
V=3.53;
Pv=73;
solve((Pr*((V^n)-(Vi^n)))/((Vr^n)-(Vi^n))==Pv,n)
The abbove code does'nt give an answer just " Empty sym: 0-by-1 "
The correct for the first one should be:
V=3.53;
Pv=73;
solve((Pr*((V^n)-(Vi^n)))/((Vr^n)-(Vi^n))==Pv,n)
ans = 2.6088704281837088027315795939332
Thanks in advance
CODE:
Vr = 12;
Vi = 3;
Pr = 5000;
syms n
V = [3;3.5;4;4.51;5;5.5;6;6.5;7;7.5;8.01;8.5;9;9.5;10;10.49;10.99;11.49;12]
Pv = [13;73;201;385;619;864;1174;1508;1894;2271;2710;3150;3523;3918;4244;4496;4711;4834;5000]
for i = 1:length(V)
n = vpasolve((Pr*((V.^n)-(Vi.^n)))/((Vr.^n)-(Vi.^n))==Pv,n)
end
n = mean(n)

採用された回答

Star Strider
Star Strider 2021 年 10 月 25 日
Another approach —
Vr = 12;
Vi = 3;
Pr = 5000;
syms n
V = [3;3.5;4;4.51;5;5.5;6;6.5;7;7.5;8.01;8.5;9;9.5;10;10.49;10.99;11.49;12];
Pv = [13;73;201;385;619;864;1174;1508;1894;2271;2710;3150;3523;3918;4244;4496;4711;4834;5000];
for i = 1:length(V)
nc{i} = vpasolve((Pr*((V(i).^n)-(Vi.^n)))/((Vr.^n)-(Vi.^n)) == Pv(i),n);
end
idx = cellfun(@(x)~isempty(x), nc)
idx = 1×19 logical array
0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
nm = sprintf('%23.15E',mean(double([nc{idx}]),'omitnan'))
nm = ' 1.173348363730592E+00'
.
  2 件のコメント
Alexander Madsen
Alexander Madsen 2021 年 10 月 25 日
Thanks, not an approach i thought abput
Star Strider
Star Strider 2021 年 10 月 25 日
As always, my pleasure!
.

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

その他の回答 (1 件)

Matt J
Matt J 2021 年 10 月 24 日
Because there is no analytical solution. Try vpasolve() or fzero() instead.
  1 件のコメント
Alexander Madsen
Alexander Madsen 2021 年 10 月 25 日
I tried both. fzero() is not allowed because n is not a datatype double. And for vpasolve() i get this error:
More equations than variables is only supported for polynomial systems.
sol = eng.feval_internal('symobj::vpasolve',eqns,vars,X0);

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

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by