Error using subs function of Symbolic Math toolbox

3 vues (au cours des 30 derniers jours)
Chala Kedir
Chala Kedir le 29 Déc 2021
Réponse apportée : Paul le 29 Déc 2021
I am using the following code to generate data to use in Non linear Least Square Estimation
syms a b S
f=@(a,b,S) a+a*b + b*S;
Data =[ ];
for i = 1:10
Data =[Data ; [i, subs(f, [a,b,S], [1,2,i])] ];
end
Error using subs
Expected input number 1, S, to be one of these types:

sym

Instead its type was function_handle.

Error in sym/subs (line 69)
validateattributes(F, {'sym'}, {}, 'subs', 'S', 1);
When I run these I get the following error.
Expected input number 1, S, to be one of
these types:
sym
Instead its type was function_handle.
Error in sym/subs (line 60)
validateattributes(F, {'sym'}, {}, 'subs','S', 1);
I don't understand which at which part I'm making mistake. I even tried by converting sym before using subs but this sill doesn't seem to work.
My MATLAB version is 2019b
  1 commentaire
Torsten
Torsten le 29 Déc 2021
Use f = a+a*b+b*S instead of f=@(a,b,S) a+a*b+b*S.

Connectez-vous pour commenter.

Réponse acceptée

Paul
Paul le 29 Déc 2021
Use Torsten's suggestion, or
syms a b S
f(a,b,S) = a+a*b + b*S;
Data =[ ];
for i = 1:10
Data =[Data ; [i, f(1,2,i)] ];
end
Data
Data = 
Or more simply
Data = [1:10; f(1,2,1:10)].'
Data = 
Is it certain that sym objects and math is needed here at all?

Plus de réponses (0)

Catégories

En savoir plus sur Symbolic Math Toolbox 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!

Translated by