MATLAB Answers

Defining equations with interpolant cfit model (ex. linearinterp, pchipinterp)

8 views (last 30 days)
Ho-Jun Suk
Ho-Jun Suk on 20 Feb 2016
Commented: Benedikt Trolp on 12 Nov 2017
Hi,
does anyone know how to define equations to be used in solve or vpasolve using interpolant cfit model?
I have pchipinterp (pchip_int_fn) and linearinterp (lin_int_fn) cfit models from my raw data and I want to define an equation like the following:
syms x y z
eqn = x*pchip_int_fn(x)*lin_int_fn(x) + y*pchip_int_fn(y)*lin_int_fn(y) + x*pchip_int_fn(z)*lin_int_fn(z) == 0
solve(eqn)
Matlab gives me an error message saying
"Error using cfit/subsref>iParenthesesReference (line 46)
Cannot evaluate CFIT model for some reason.
Error in cfit/subsref (line 16)
out = iParenthesesReference( obj, currsubs );"
Does anyone know how to resolve this issue?
Thank you so much for your help!

  0 Comments

Sign in to comment.

Accepted Answer

Anish Mitra
Anish Mitra on 24 Feb 2016
cfit objects do not work with inputs as symbolic variables. To work around this, you could re-write the cfit model equation using symbolic variables and then use it in 'eqn', instead of calling the cfit object.
The other option you could explore to find results for x,y,z is using the Optimization Toolbox, and minimizing the square of the value of 'eqn'. This would be a numerical optimization, and symbolic variables would not be used.

  3 Comments

Ho-Jun Suk
Ho-Jun Suk on 24 Feb 2016
Thank you so much Anish! I could not figure out how to find the equations of interpolant cfit models (when I look at the information on the fit model, it returns ans(x) = piecewise polynomial computed from p Coefficients: p = coefficient structure), so I could not use your first option, but the second option works well! Thank you again!
Anish Mitra
Anish Mitra on 25 Feb 2016
Yes, the first option would not be possible for piecewise polynomials. It would work for continuous functions (regular polynomials or exponentials).
Benedikt Trolp
Benedikt Trolp on 12 Nov 2017
Hello Anish, I'm facing a similar Problem to the original poster, but having a hard time executing your second Option. Could you maybe explain it in Detail ? Thanks alot in advance

Sign in to comment.

More Answers (0)