Duda con optimización en scilab
Publicado por Carol89 (5 intervenciones) el 14/03/2012 20:27:11
Hola a todos soy novata en este foro y espero ue alguien me pueda ayudar.Tengo que implementar una función para encontran un máximo empleando el método de la sección aurea, sin embargo al ejecutarlo no consigo que entre en ciclo while y me imprime xopt inicial de ese ciclo que no es el que me interesa.Ojala alguien me ayude a encontrar el error .Muchas gracias os adjunto el programa que para los parametros dados.muchas gracias
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
deff('fx=ec(x)','fx=2*sin(x)-(x^2/10)');
xlow=0xhigh=4maxit=1000es=0.000001
opcion=1function [xopt,fopt,iter,ea]=goldmax(xlow,xhigh,maxit,fx)
xl=xlow xh=xhigh iter=1d=(xh-xl)*((sqrt(5)-1)/2*(xh-xl))
x1=xl+d
x2=xh+d
f1=ec(x1)
f2=ec(x2)
if f2<f1 then xopt=x1 fopt=f1else
xopt=x2 fopt=f2end
es=0.00001
ea=es*10
while ea>es & iter<maxit
iter=iter+1
d=d*R
if f1>f2 then xl=x2 x2=x1x1=xl+d
f2=f1f1=ec(x1)
else
xh=x1 x1=x2x2=xh-d
f1=f2f2=ec(x2)
end
if f1>f2 then xopt=x1 fopt=f1else
xopt=x2 fopt=f2end
if xopt~=0ea=100*(1-R)*abs((xh-xl)/xopt)
end
end
endfunction
[xopt,fopt,iter,ea]=gold(xlow,xhigh,maxit,ec)
disp(xopt)
Valora esta pregunta


0
