Solve equation with multiple values for V
5 views (last 30 days)
Show older comments
Alexander Madsen
on 24 Oct 2021
Commented: Star Strider
on 25 Oct 2021
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 Comments
Accepted Answer
Star Strider
on 25 Oct 2021
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'))
.
2 Comments
More Answers (1)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!