Curve fitting with a custom equation

Hi all,
I'm trying to fit a custom equation but it seems I wrote not in the correct way or somethinkg similar (I'm quite new to Matlab)...
The equation is
u+(f-u)/(1+exp((-H/1.9872)*(1/x-1/m)+(C/1.9872)*[((m/x)-1)+log(x/m)]))
and the error message claims
Fit Name: untitled fit 1
Error: Expression u+(f-u)/(1+exp((-H/1.9872)*(1/x-1/m)+(C/1.9872)*[((m/.x)-1)+log(x/m)])) is not a valid MATLAB expression, has non-scalar coefficients, or cannot be evaluated:
Error in fittype expression ==> u+(f-u)./(1+exp((-H./1.9872).*(1./x-1./m)+(C./1.9872).*[((m./.x)-1)+log(x./m)]))
??? Invalid use of operator.
Do you have suggestions?
Thanks
Marco

답변 (2개)

Torsten
Torsten 2025년 10월 10일

0 개 추천

Only round brackets are allowed in your expression. But maybe there are additional problems.
If the code does not work after replacing [ ] by ( ), you should post your MATLAB code for inspection.

댓글 수: 6

Marco Sette
Marco Sette 2025년 10월 10일
Thanks for your suggestion. It does not work after replacing [] with ().
I have no code, I simply used
Curve fitter app
Fit type : Custom equation
Wrote the equation in the upper right panel, after importing the data
Torsten
Torsten 2025년 10월 10일
Follow the instructions given here:
Especially:
  1. On the Curve Fitter tab, in the Export section, click Export and select Generate Code.The Curve Fitter app generates code from your session and displays the file in the MATLAB Editor. The file includes the currently selected fit in your session and its opened plots. The file captures the following information:
  • Name of the fit and its variables
  • Fit settings and options
  • Plots
  • Curve or surface fitting object and the function used to create the fit:
  • cfit or sfit object representing the fit
  • A structure with goodness-of-fit information
2. Save the file.
Torsten
Torsten 2025년 10월 10일
편집: Torsten 2025년 10월 10일
Another possible problem could be that x=0 is a data point and you divide by 0 in 1/x or that x/m becomes negative in log(x/m).
Image Analyst
Image Analyst 2025년 10월 10일
You could help us help you by attaching the data you are using to train the fit.
Marco Sette
Marco Sette 2025년 10월 10일
편집: Marco Sette 2025년 10월 10일
Hi Torsten,
x values range from 293 to 363 K.
I will check tomorrow the procedure you suggest.
Many thanks
Marco
In your fittype expression, there is another error:
m/.x
should be replaced by
m./x
or at least
m/x

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

Marco Sette
Marco Sette 2025년 10월 11일

0 개 추천

Hi all,
it seems to work now. I've simply rewritten the equation without differences...
The script is attached.
The results are similar to the published ones (this is a test similar to literature).
I need to adjust some parameters but it seems I'm on the right way..
Thanks a lot for your kind help, it was very useful :)
Best
Marco

카테고리

도움말 센터File Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

제품

릴리스

R2024b

태그

질문:

2025년 10월 10일

답변:

2025년 10월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by