We can meet this requirement using either option 1 or option 2, discussed below. In either case, we have used the data sample "carsmall," which comes with the Statistics and Machine Learning Toolbox.
Option 1: Using "fit"
Below is an example that demonstrates the required fit. This workflow requires the Curve Fitting Toolbox:
load carsmall
fo = fitoptions('Method','NonlinearLeastSquares', 'Normalize', 'on', 'Robust', 'LAR','StartPoint',[1 1 1 1]);ft = fittype('C0+C1*x^(n-3)+C2*x^(n-2)+C4*x^n','problem','n','options',fo);[curve2,gof2] = fit(Weight,Horsepower,ft,'problem',4);plot(curve2,Weight,Horsepower)
Result using fit:
For options on fine-tuning the curve fitting, please see the below documentation links:
"fitoptions":
Option 2: Using "fitlm"
Below is an example that demonstrates the required fit using a term matrix. This workflow requires the :
Here is an alternative way to achieve the required fit, without using a terms matrix.
load carsmall
lm = fitlm(Weight,Horsepower,'y~x1^4 - x1:x1:x1');
plot(lm)
For more information, please look into the below documentation link on "fitlm":