Using interp1 within vpasolve

조회 수: 9 (최근 30일)
Adam Zieser
Adam Zieser 2021년 7월 13일
댓글: Walter Roberson 2021년 7월 14일
I'm having difficulty with the following situation trying to numerically solve an equation (with vpasolve, or something similar) that uses interp1-interpolated data within the solve. Consider:
with implementation:
syms Z;
vpasolve(Z.^4 == ( muL .* interp1(X,GH,Z) - muH .* interp1(X,GL,Z) )./( muL .* interp1(X,FH,Z) ...
- muH .* interp1(X,FL,Z) ), Z);
where and are constants, so that the μ-values are constant, and F and G are 2D matrices squeezed to 1D. These 1D matrices are known on a grid Z = 5:15. Then, I'm attempting to solve this equation for Z, which presumably has real-numbered values as solution. I assumed vpasolve worked iteratively, with an initial guessed query of Z, such that interp1 with (syms Z) is valid to use inside vpasolve. Of course, this doesn't work.
Is there any way to work this? I've simplified things for ease of explanation, but suffice it to say that just doing a polynomial fit on F and G instead of using interp1 is not on the table: the data in the F and G grids need to only be interpolated for non-integer values of Z. Here's some data, just to make it easier to run if needed.
muH = 0.178125;
muL = 0.142500;
GL = [0.2684 0.2690 0.2696 0.2704 0.2714 0.2724 0.2734 0.2746 0.2756 0.2768 0.2781];
GH = [0.3258 0.3280 0.3307 0.3342 0.3381 0.3431 0.3474 0.3520 0.3568 0.3618 0.3670];
FL = 1E-6 .* [0.4234 0.4180 0.4100 0.4017 0.3932 0.3840 0.3766 0.3698 0.3628 0.3554 0.3480];
FH = 1E-6 .* [0.4234 0.4180 0.4100 0.4017 0.3932 0.3840 0.3766 0.3698 0.3628 0.3554 0.3480];

채택된 답변

Walter Roberson
Walter Roberson 2021년 7월 14일
Turn it into a numeric system
z0 = 1;
muH = 0.178125;
muL = 0.142500;
GL = [0.2684 0.2690 0.2696 0.2704 0.2714 0.2724 0.2734 0.2746 0.2756 0.2768 0.2781];
GH = [0.3258 0.3280 0.3307 0.3342 0.3381 0.3431 0.3474 0.3520 0.3568 0.3618 0.3670];
FL = 1E-6 .* [0.4234 0.4180 0.4100 0.4017 0.3932 0.3840 0.3766 0.3698 0.3628 0.3554 0.3480];
FH = 1E-6 .* [0.4234 0.4180 0.4100 0.4017 0.3932 0.3840 0.3766 0.3698 0.3628 0.3554 0.3480];
best_z = fsolve(@(Z) Z.^4 - (( muL .* interp1(X,GH,Z,'linear','extrap') - muH .* interp1(X,GL,Z,'linear','extrap') )./( muL .* interp1(X,FH,Z,'linear','extrap') ...
- muH .* interp1(X,FL,Z,'linear','extrap') )), z0);
Unrecognized function or variable 'X'.

Error in solution (line 10)
best_z = fsolve(@(Z) Z.^4 - (( muL .* interp1(X,GH,Z) - muH .* interp1(X,GL,Z) )./( muL .* interp1(X,FH,Z) ...

Error in fsolve (line 260)
fuser = feval(funfcn{3},x,varargin{:});

Caused by:
Failure in initial objective function evaluation. FSOLVE cannot continue.
  댓글 수: 5
Adam Zieser
Adam Zieser 2021년 7월 14일
Ah, yes, had to download the Optimization Toolbox. Thanks a bunch!
Walter Roberson
Walter Roberson 2021년 7월 14일
Could also have used fzero in this case.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Equation Solving에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by