Reputation: 21
I have a relatively complex non-linear system to solve in MATLAB, which can be described as a function of unknown coefficients and basis functions, that I am trying to fit to some initial trajectory data to get the coefficients.
I currently have a working solution using MATLAB's fittype function, but it is limited as only scalar values can be input as coefficients, whereas I need to run this fit multiple times using a different number of unknown coefficients Xi to quantify my wider algorithm's performance with a varying number of basis functions. An example of the fit is below:
s1_fit_1 = fittype( @(xi1, xi2, xi3, xi4, xi5, xi6, xi7, xi8, xi9, xi10, r1_1, v1_1, t) ...
( (( chebyshevT((mBasis-1), (time_to_z(t0, t1, t)))' ...
- (omega1(getT1(t), dt1)' .* h0) ...
- (omega2(getT1(t), dt1)' .* hf) ...
- (omega3(getT1(t), dt1)' .* h0_dot) ...
- (omega4(getT1(t), dt1)' .* hf_dot))' * [xi1; xi2; xi3; xi4; xi5; xi6; xi7; xi8; xi9; xi10]) ...
+ (omega1(getT1(t), dt1) * r0_1) ...
+ (omega2(getT1(t), dt1) * r1_1) ...
+ (omega3(getT1(t), dt1) * v0_1) ...
+ (omega4(getT1(t), dt1) * v1_1) ), ...
'independent', 't', 'dependent', 's1_r_1', ...
'coefficients', {'xi1', 'xi2', 'xi3', 'xi4', 'xi5', 'xi6', 'xi7', 'xi8', 'xi9', 'xi10', 'r1_1', 'v1_1'});
For reference, functions omega[x] and time_to_z() are not affected by this and can be neglected.
As you can see I currently have 10 Xi[x] coefficients; I would like to vary this number over multiple script runs, up to approximately 50 as a maximum. It can be done manually, but that would be very time-consuming. The simplest way for me to do this would be to define Xi as a vector or cell where I dynamically update the size, but fittype does not seem to support this.
Is there a way for me to achieve this, or perhaps another non-linear solver I can use that would achieve the same result?
Many thanks.
Upvotes: 1
Views: 79
Reputation: 494
vector-valued coefficients are better supported by function lsqcurvefit
from Optimization Toolbox:
https://www.mathworks.com/matlabcentral/answers/470283-using-a-vector-of-coefficients-in-fittype
Upvotes: 0