Solve the equation with variable
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
onur karakurt
il 28 Apr 2020
Commentato: Star Strider
il 1 Mag 2020
function x = enthalpy(h)
eqn=@(x,h) 38.0657.*(( -x.*((3*0.605719400e-7)./x.^4 - 17.275266575 + (2*-0.210274769e-4)./x.^3 + (-0.158860716E-3)./x.^2 - (2.490888032)./x - (3*(-0.195363420E-3).*x.^(1/2))/2 + ((0.791309509)*(25.36365)*exp(-(25.36365).*x))./(exp(-(25.36365).*x) - 1) + ((0.212236768)*(16.90741)*exp(-(16.90741).*x))./(exp(-(16.90741).*x) - 1) - ((-0.197938904)*(87.31279)*exp((87.31279).*x))./(exp((87.31279).*x) + 2/3)))+1)./x - h;
x = solve(@(x,h)eqn==0,x,options)
end
h is changable. functiıon is not giving a answer. how can ı solve this function
0 Commenti
Risposta accettata
Star Strider
il 28 Apr 2020
A bit of editing is in order, and a different optimisation function.
Try this:
eqn=@(x,h) 38.0657.*(( -x.*((3*0.605719400e-7)./x.^4 - 17.275266575 + (2*-0.210274769e-4)./x.^3 + (-0.158860716E-3)./x.^2 - (2.490888032)./x - (3*(-0.195363420E-3).*x.^(1/2))/2 + ((0.791309509)*(25.36365)*exp(-(25.36365).*x))./(exp(-(25.36365).*x) - 1) + ((0.212236768)*(16.90741)*exp(-(16.90741).*x))./(exp(-(16.90741).*x) - 1) - ((-0.197938904)*(87.31279)*exp((87.31279).*x))./(exp((87.31279).*x) + 2/3)))+1)./x - h;
x0 = 1;
x = fminsearch(@(x)norm(eqn(x,h)),x0)
There are several functions that would likely work, including fminunc and others. The solve function is only for symbolic functions, so it is not appropriate here.
Since you want to solve for ‘x’ that is the only varialbe the optimisation function needs to know about, so while both values need to be passed to the function, only ‘x’ is important to the optimisation. You are finding the minimum between the function and ‘h’, and the norm function optimises that. (It is the easiest to use here.)
4 Commenti
Star Strider
il 1 Mag 2020
I do not understand what the problem is, or what the ‘correct value’ is. Nonlinear parameter estimation routines are very sensitive to the starting value (here ‘x0’). Experiment with different values for it to get different results. I get the same result for ‘x’ (0.1895) with several different solvers (for example fminsearch, fminunc) in R2020a with the code you posted.
Più risposte (2)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!