I dont understand, i try to use solve to find x in Matlab Function Block
2 次查看(过去 30 天)
显示 更早的评论
function x = fcn(y)
sym a;
r1=7.3e-5;
r2=-1.1e-7;
s1=1.6e-1;
s2=1.38e-3;
s3=-1.6e-5;
t1=1.60e-2;
t2=-1.3;
t3=4.12e2;
A=0.25;
Tel=25;
sol =double(solve( 1.297 + (r1+r2)*Tel*a/A + (s1 + s2*Tel + s3*(Tel^2))*log(((t1 + t2/Tel + t3/(Tel^2))*a/A)+1)-y,a));
x = sol;
0 个评论
采纳的回答
Walter Roberson
2022-1-18
has shown you how to solve the equation using syms
However, syms requires the MATLAB Interpreter, and so is only available in a MATLAB Function block if you have rapid acceleration turned off completely (or sometimes on the next setting if you are careful); it cannot be used if you need code generation to C or C++ code or deployment.
If you need to generate code or you need deployment, then you need a different approach: you need to use fzero() or fsolve() to find the root of the expression, or you need to work with the formula to find the general solution.
MATLAB is not able to find the general formula, but using Maple, and letting the 1.297 be named C, then
r1=7.3e-5;
r2=-1.1e-7;
s1=1.6e-1;
s2=1.38e-3;
s3=-1.6e-5;
t1=1.60e-2;
t2=-1.3;
t3=4.12e2;
A=0.25;
Tel=25;
C = 1.297;
a = ((Tel^2*s3 + Tel*s2 + s1) * (Tel^2*t1 + Tel*t2 + t3) * ...
lambertw(Tel^3 * (r1+r2) * ...
exp((Tel^3 * (r1+r2) - t1 * (C-y) * Tel^2 - t2 * (C-y) * Tel - t3 * (C-y)) / ...
(Tel^2 * s3 + Tel * s2 + s1) / ...
(Tel^2 * t1 + Tel * t2 +t3)) / ...
(Tel^2 * s3 + Tel * s2 + s1) / ...
(Tel^2 * t1 + Tel * t2 + t3)) ...
- Tel^3 * (r1+r2)) ...
* A / Tel / (r1+r2) / (Tel^2 * t1 + Tel * t2 + t3)
3 个评论
Walter Roberson
2022-1-19
opt = optimoptions('Algorithm', 'Levenberg-Marquardt');
iel = fsolve(f, uel, opt);
Walter Roberson
2022-1-19
syms x uel
f = uel - (3 + 3 * x + 5 * log(3 * x + 1))
solve(f, x)
string(ans)
This tells you that there is a direct solution without using fsolve, using the wrightOmega function
However, wrightOmega is part of the Symbolic Toolbox, and so probably cannot have code generated for it.
You might, however, be able to take advantage of https://www.mathworks.com/matlabcentral/fileexchange/56407-wrightomegaq
更多回答(1 个)
Voss
2022-1-18
编辑:Voss
2022-1-18
Looks like you should use syms rather than sym
fcn(0)
function x = fcn(y)
syms a;
r1=7.3e-5;
r2=-1.1e-7;
s1=1.6e-1;
s2=1.38e-3;
s3=-1.6e-5;
t1=1.60e-2;
t2=-1.3;
t3=4.12e2;
A=0.25;
Tel=25;
sol = double(solve( 1.297 + (r1+r2)*Tel*a/A + (s1 + s2*Tel + s3*(Tel^2))*log(((t1 + t2/Tel + t3/(Tel^2))*a/A)+1)-y,a));
x = sol;
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calculus 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!