How to minimize a vector using a vector input?
Show older comments
Hi everyone, below there is my function whose output needs to be minimized. This function accepts as input a vector h which is used to evaulate the matrix Twan (Temperature Wall Analytical). Then, the square differences between two matrix is evaluated. So, I need to minimize the vector f using the vector h! Could you help me? Thanks a lot!
function f=thetamethodfun2D(h)
global L Grid beta frames b p Taw Ti Twsp phi phitrue dt k Tamb dx T_new_b cont
% h=x; sigma=5.67e-8; eps=0.91;
%% % Modifica matrice Laplaciano
for i=1:b-2 par=k/(2*dx) * 1/( -3*k/(2*dx) - h(i+1) ); L(i,i)= L(i,i)+ (-4)*par;
L(i+(b-2),i)=L(i+(b-2),i) + par;
end
I=speye(size(L)); A=I-beta*L;
%% Ciclo temporale
Tan_matr2=Ti; Tan_vet_old2=Tan_matr2(Grid>0);
for it=1:frames
%%%Effetto Boundary conditions
T_new_b(:,1)=(sigma*eps)./(( -3*k/(2*dx) - h(:) )).* (Twsp(:,it).^4 - Tamb^4) - h(:)*Taw./(( -3*k/(2*dx) - h(:) ));
T_bordo2=4*del2(T_new_b,dx);
T_b2=T_bordo2(Grid>0);
Tan_vet_new2=A\(Tan_vet_old2) + A\(beta*dx*dx*T_b2);
Tan_matr2=T_new_b;
Tan_matr2(Grid>0)=Tan_vet_new2;
% Per neumann (derivata al primo ordine)
Tan_matr2(1,2:end)=Tan_matr2(2,2:end);
Tan_matr2(end,2:end)=Tan_matr2(end-1,2:end);
Tan_matr2(:,1)= (Tan_matr2(:,3) - 4*Tan_matr2(:,2)).*(k/(2*dx) .* 1./( -3*k/(2*dx) - h(:) )) + Tan_matr2(:,1);
%%%%
Twan(:,it)=Tan_matr2(:,1);
% Aggiornamento
Tan_vet_old2 =Tan_vet_new2;
end
f=sum((Twan'-Twsp').^2);
cont=cont+1;
% if cont==b % keyboard % cont=0; % end end
Answers (0)
Categories
Find more on Debugging and Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!