getting error in line 5 please help
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
functin=@(x) (3*(-1-212*x)^2+(-1-212*x)-4*(4-170*x)-7)^2+(4-170*x-1-212*x2)^2;
ta3ot=0.001;
Up_limit=2;
Low_limit=0;
[min_x,y_min]=golden_cut(functin,ta3ot,Up_limit,Low_limit); %%%%%%%%%%% hereeeeeeeeeeeeeeeeeeeeeeeeeeee
function[min_x,y_min]=golden_cut(functin,ta3ot,Up_limit,Low_limit)
x1=Low_limit+0.381966*(Up_limit-Low_limit);
x2=Low_limit+0.618034*(Up_limit-Low_limit);
while(sqrt((x2-x1)^2)>ta3ot)
if(functin(x1)>functin(x2))
Low_limit=x1;
x1=x2;
x2=Low_limit+0.618034*(Up_limit-Low_limit);
else
Up_limit=x2;
x2=x1;
x1=Low_limit+0.381966*(Up_limit-Low_limit);
end
end
min_x=(x1+x2)/2;
y_min=(functin(x1)+functin(x2))/2;
end
0 commentaires
Réponses (3)
Sardar Usama
le 2 Juil 2021
The error is in line-1.
functin=@(x) (3*(-1-212*x)^2+(-1-212*x)-4*(4-170*x)-7)^2+(4-170*x-1-212*x2)^2;
x2 is undefined in above line.
0 commentaires
Star Strider
le 2 Juil 2021
The error refers to ‘x2’ not being defined in ‘functin’:
functin=@(x) (3*(-1-212*x)^2+(-1-212*x)-4*(4-170*x)-7)^2+(4-170*x-1-212*x2)^2;
↑ ← HERE
Since it is not obvious whether this is a simple typographical error or if it supposed to be ‘x*2’ or ‘x^2’ (or perhaps something else), you have to determine what you want, and fix it. With that ambiguity resolved, the code runs without error.
% functin=@(x) (3*(-1-212*x)^2+(-1-212*x)-4*(4-170*x)-7)^2+(4-170*x-1-212*x2)^2;
% ta3ot=0.001;
% Up_limit=2;
% Low_limit=0;
% [min_x,y_min]=golden_cut(functin,ta3ot,Up_limit,Low_limit); %%%%%%%%%%% hereeeeeeeeeeeeeeeeeeeeeeeeeeee
%
% function[min_x,y_min]=golden_cut(functin,ta3ot,Up_limit,Low_limit)
% x1=Low_limit+0.381966*(Up_limit-Low_limit);
% x2=Low_limit+0.618034*(Up_limit-Low_limit);
% while(sqrt((x2-x1)^2)>ta3ot)
% if(functin(x1)>functin(x2))
% Low_limit=x1;
% x1=x2;
% x2=Low_limit+0.618034*(Up_limit-Low_limit);
% else
% Up_limit=x2;
% x2=x1;
% x1=Low_limit+0.381966*(Up_limit-Low_limit);
% end
% end
% min_x=(x1+x2)/2;
% y_min=(functin(x1)+functin(x2))/2;
% end
.
0 commentaires
Voir également
Catégories
En savoir plus sur Signal Processing 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!