I dont understand, i try to use solve to find x in Matlab Function Block
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
huy duc
am 18 Jan. 2022
Kommentiert: Walter Roberson
am 19 Jan. 2022
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 Kommentare
Akzeptierte Antwort
Walter Roberson
am 18 Jan. 2022
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 Kommentare
Walter Roberson
am 19 Jan. 2022
opt = optimoptions('Algorithm', 'Levenberg-Marquardt');
iel = fsolve(f, uel, opt);
Walter Roberson
am 19 Jan. 2022
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
Weitere Antworten (1)
Voss
am 18 Jan. 2022
Bearbeitet: Voss
am 18 Jan. 2022
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 Kommentare
Siehe auch
Kategorien
Mehr zu Calculus finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!