How do I create a series of variables (V0, V1, ...Vn) which act as independent variables in conjunction with a series of sums?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Domantas Laurinavicius
le 1 Fév 2021
Modifié(e) : Domantas Laurinavicius
le 4 Fév 2021
Basically, I have a symsum which I intend on feeding into a fittype() function.
The fittype is of the form (V0/2) + (V1/2)*cos(1*x) + (V2/2)*cos(2*x) +... (Vn/2)*cos(n*x) where each Vn is an independent variable in a non-linear least squares.
Those Vn variables are going into a matrix so the values need to be extractable, right now I'm using coeffvalues(fitresult) or manually getting them out with fitresult.V0, V1 etc (that could be a question on its own).
I have the sum of cos funcs
syms x n
Func = symsum((1/2)*cos(n*x),n,[1 5])
but I can't figure out how to (1) create an array of variables V0:Vn and outputting them as variables and (2) how to combine those with a symsum output into the fittype given above.
0 commentaires
Réponse acceptée
Chaitanya Mallela
le 4 Fév 2021
Modifié(e) : Chaitanya Mallela
le 4 Fév 2021
fittype function accepts character array as input argument but the symsum function gives symbolic variable. To apply fittype to this function you need to split the symsum expression into terms and convert them to character array and generate independent variable Vn as coefficients to fittype function.
syms x n
Func = cell2sym(children(symsum((1/2)*cos(n*x),n,[1 5])));
g = fittype(arrayfun(@char,Func,'UniformOutput',false),'coefficients',arrayfun(@char,sym('V',[1,5]),'UniformOutput',false))
1 commentaire
Domantas Laurinavicius
le 4 Fév 2021
Modifié(e) : Domantas Laurinavicius
le 4 Fév 2021
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Linear and Nonlinear Regression dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!