Solve equation with multiple values for V
5 次查看(过去 30 天)
显示 更早的评论
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)
0 个评论
采纳的回答
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)
nm = sprintf('%23.15E',mean(double([nc{idx}]),'omitnan'))
.
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!