Solve the equation with variable
조회 수: 3 (최근 30일)
이전 댓글 표시
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
채택된 답변
Star Strider
2020년 4월 28일
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
Star Strider
2020년 5월 1일
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.
추가 답변 (2개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Number Theory에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!