Solve equation with multiple values for V

5 views (last 30 days)
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
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 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)
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'
.
Star Strider on 25 Oct 2021
As always, my pleasure!
.

Matt J on 24 Oct 2021
Because there is no analytical solution. Try vpasolve() or fzero() instead.
Alexander Madsen on 25 Oct 2021
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);