Converting symbolic expression into double.
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
When I perform a series of functions, the result is:
1.009168*rS + 0.25*rS*dcellCurrent(1) + 0.157*rS*dcellCurrent(2) + 0.057*rS*dcellCurrent(3) - 0.002*rS*dcellCurrent(4) - 0.093*rS*dcellCurrent(5) - 0.145*rS*dcellCurrent(6) - 0.197*rS*dcellCurrent(7) - 0.232*rS*dcellCurrent(8) - 0.313*rS*dcellCurrent(9) ... *exp((120843*iSat*rSh)/(3125*n)))/(3125*n*exp((120843*rSh*dcellCurrent(13))/(3125*n))))
The expression is extremely long, I cut out a good bit of its innards so it would be viewable here. When I copy and paste the expression that it shows into the command window, the result is this number: 13.076812258420913
I know that I can just copy and paste it, but I would like to use logical expressions in an if statement, and I need to convert the expression in code because I would not like to do it by hand. How should I go about converting?
0 Commenti
Risposta accettata
Più risposte (1)
Walter Roberson
il 19 Lug 2011
You should use subs() to substitute the current values of the variables in to the expression, and you should use double() on the result to convert it from a symbolic number to a double precision value.
6 Commenti
Walter Roberson
il 19 Lug 2011
You do not appear to have defined dcellCurrent.
Anyhow:
syms x dcC
S = simplify(solve(iP - iSat * (exp(38.66976*(x+dcC*rS)/n)-1) -(dcC*rS + x)/rSh - dcC));
subtotal = 0;
for K = 1:length(dcC)
subtotal = subtotal + (double(subs(S,dcC,dcellCurrent(K))-dcellVoltage(K)).^2;
end
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!