Matlab - Correccion de Programacion

 
Vista:

Correccion de Programacion

Publicado por Cesar (2 intervenciones) el 22/09/2016 21:57:41
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
clear all, clf, global t O DBOu O0 Os
DBOu=20; Os=8.8;
t=[0 .083 .16 .25 .5 .75 1 2 3 4 5 6 7 8 9 10]';
O=[8.3 8 7.9 7.8 7.7 7.6 7.4 7.2 7 6.8 8.3 6.1 5.6 5.2 4.8 4.2]';  O0=O(1);
Opciones=optimset('TolX',1e-20,'TolFun',...
         1e-20,'MaxFunEvals',10000)
Est=fminsearch('AutodepurMin',[0.4 0.9],Opciones);
k1=Est(1); k2=Est(2)
tc=linspace(t(1),t(length(t)),100);
Oc=Os-k1*DBOu/(k2-k1)*exp(-k1*tc)+(k1*...
    (Os+DBOu-O0)+k2*(O0-Os))/...
    (k2-k1)*exp(-k2*tc);
plot(tc,Oc,'k-','LineWidth',1), hold on, plot(t,O,'ko')
axis([0 10 3.5 9])
ylabel('\fontsize{13} Conc. de Oxígeno (mg/L)')
xlabel('\fontsize{13}Tiempo (días)')
text(3,8.65,'\fontsize{13}Conc. de oxígeno a saturación')
line([t(1) t(length(t))],[Os Os],'Color','k','LineWidth',1)
 
Text1=['\fontsize{13}k_1= ',num2str(round(1000*k1)/1000)];
Text2=['\fontsize{13}k_2= ',num2str(round(100*k2)/100)];
text(7,4.5,Text1),  text(7,4,Text2)
%----------------------------------------------------------
%------ Funcion llamada por Autodepur.m -----------
function q=AutodepurMin(p);
global t O DBOu O0 Os
k1=p(1);       k2=p(2);
Oc=Os-k1*DBOu/(k2-k1)*exp(-k1*t)+...
   (k1*(Os+DBOu-O0)+k2*(O0-Os))/(k2-k1)*exp(-k2*t);
Error=O-Oc;    q=sum((Error).^2);
%--------------------------------------------------
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
-2
Responder
Imágen de perfil de JOSE JEREMIAS CABALLERO
Val: 6.975
Oro
Ha mantenido su posición en Matlab (en relación al último mes)
Gráfica de Matlab

Correccion de Programacion

Publicado por JOSE JEREMIAS CABALLERO (5917 intervenciones) el 23/09/2016 23:59:05
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
function optimizacion1
 clf, global t O DBOu O0 Os
DBOu=20; Os=8.8;
t=[0 .083 .16 .25 .5 .75 1 2 3 4 5 6 7 8 9 10]';
O=[8.3 8 7.9 7.8 7.7 7.6 7.4 7.2 7 6.8 8.3 6.1 5.6 5.2 4.8 4.2]';  O0=O(1);
Opciones=optimset('TolX',1e-20,'TolFun',...
         1e-20,'MaxFunEvals',10000);
Est=fminsearch(@AutodepurMin,[0.4 0.9],Opciones);
k1=Est(1); k2=Est(2);
tc=linspace(t(1),t(length(t)),100);
Oc=Os-k1*DBOu/(k2-k1)*exp(-k1*tc)+(k1*...
    (Os+DBOu-O0)+k2*(O0-Os))/...
    (k2-k1)*exp(-k2*tc);
plot(tc,Oc,'k-','LineWidth',1), hold on, plot(t,O,'ko')
axis([0 10 3.5 9])
ylabel('\fontsize{13} Conc. de Oxígeno (mg/L)')
xlabel('\fontsize{13}Tiempo (días)')
text(3,8.65,'\fontsize{13}Conc. de oxígeno a saturación')
line([t(1) t(length(t))],[Os Os],'Color','k','LineWidth',1)
 
Text1=['\fontsize{13}k_1= ',num2str(round(1000*k1)/1000)];
Text2=['\fontsize{13}k_2= ',num2str(round(100*k2)/100)];
text(7,4.5,Text1),  text(7,4,Text2)
end
%----------------------------------------------------------
%------ Funcion llamada por Autodepur.m -----------
function q=AutodepurMin(p)
global t O DBOu O0 Os
k1=p(1);       k2=p(2);
Oc=Os-k1*DBOu/(k2-k1)*exp(-k1*t)+...
   (k1*(Os+DBOu-O0)+k2*(O0-Os))/(k2-k1)*exp(-k2*t);
Error=O-Oc;    q=sum((Error).^2);
%--------------------------------------------------
end

Saludos.
JOSE JEREMÍAS CABALLERO
Asesoría online en Matlab
Servicios de programación matlab
[email protected]
El correo es para servicios de programación, toda ayuda gratuita es vía foro.


http://matlabcaballero.blogspot.com

optimizacion1
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Correccion de Programacion

Publicado por Cesar (2 intervenciones) el 26/09/2016 14:17:45
Estimado jeremiasl aintentar correr el programa me sale este mensaje
>> optimizacion1
Error: File: fminsearch.m Line: 101 Column: 1
This statement is not inside any function.
(It follows the END that terminates the definition of the function "fminsearch".)

Error in optimizacion1 (line 8)
Est=fminsearch(@AutodepurMin,[0.4 0.9],Opciones);

y si saco @
me dice
>> optimizacion1
Error using optimizacion1>AutodepurMin (line 29)
Not enough input arguments.

Error in optimizacion1 (line 8)
Est=fminsearch(AutodepurMin,[0.4 0.9],Opciones);


que puede ser?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar