Fittype with anonymous function of multiple parameters and variables
Show older comments
Dear Matlab users,
I'm new to Matlab so I apologize if the solution to my problem is obvious.
I want to do two fit in a row, the second fit taking as input two values calculated through the first fit.
I have been reading about the anonymous functions in order to give as input to the second fit two variables and not parameters to optimize, I don't know what I'm missing but it does not work...
My first fit :
data = readtable("SF.xlsx");
tab_0 = data(data.C == 0,:);
[xData, yData] = prepareCurveData( tab_0.Dose, tab_0.SF );
ft0 = fittype( 'exp(-(a*x+b*x*x))', 'independent', 'x', 'dependent', 'y' );
opts.StartPoint = [0.678735154857773 0.757740130578333];
[ModelFit0,fitresult0, gof0] = fit( xData, yData, ft0, opts );
Now I want my second fit to optimize parameter gamma according to variables x and y and formula 'exp(-(alpha*x+beta*x*x))*exp(-(gamma*x*y))' with
alpha = ModelFit0.a;
beta = ModelFit0.b;
I tried
alpha = ModelFit0.a;
beta = ModelFit0.b;
ft0 = fittype( @(gamma,x,y) exp(-(alpha*x+beta*x*x))*exp(-(gamma*x*y)), 'independent', 'x', 'dependent', 'y' );
but it seems to be a problem between coefficients and parameters...
Has someone an idea how to solve this issue?
Many thanks for your help!
2 Comments
Matt J
on 3 Jul 2023
You haven't shown us the result of running the code, so we don't know what problem you're seeing.
Please provide copy-pastes of any error messages and attach the .xlsx input file. Ideally, you would just run the code for us here, using the forum's Matlab engine.
Accepted Answer
More Answers (0)
Categories
Find more on Linear Predictive Coding in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!