I am trying to ask the user for a function of x that can be used subsequently in the code. I tried to use str2func but that is throwing an error
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Ariit Sengupta
le 1 Août 2021
Commenté : Ariit Sengupta
le 1 Août 2021
str = input('Give a function to minimize in x: ','s') ;
f = "@x" +str; %%str2func(['@x '.*str]) ;
f = str2func(f);
%%Initializations
gr=double(0.5*(sqrt(5)-1)); % golden ratio
iter=0; %iteration counter
%%Initial Calculations
x1=l+(1-gr)*(u-l);
x2=l+gr*(u-l);
y1=f(l);
y2=f(u);
0 commentaires
Réponse acceptée
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Numeric Types 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!