how use "fsolve" of "fmincon" in a for loop ?

2 views (last 30 days)
jorge rodriguez
jorge rodriguez on 31 Mar 2013
Hi guys, right now im kindda in a big problem and some help will be very appreciate it. I have to find 3 parameters from a viscoelastic model by curve fitting experimental data to an equation, yes¡¡¡¡ it has complex numbers in facct Lfact should be the imaginary part of the vector but i split the complex equation into two parts already to get real data. This equation determines the complex modulus of a viscoelastic model. Y The objective equation goes as follows:
function Km=CM(S,w,a,W,z) dataexp; %E=208E9; %M0=5E4; %factor=E/M0; w = 2*pi*[10 20 30 40 50 60 70 80 90 100 200 300 415 500 600 700 800 900 1000 2000 3000 4150]; %G = [3.3 4.7 5.7 6.4 7.1 8 9 9.1 10 11.2 13.7 16.1 22 22.5 24.0 26.7 31.4 32.0 32.8 45.2 51.8 62]*1e5; %Lfact = [.97 1 1.01 1.03 1.06 1.06 1.06 1.06 1.06 1.05 1 .96 .93 .924 .918 .91 .9 .88 .83 .73 .7 .62]; %G=G.*factor; %VEfact=1e-10; %G2=Lfact.*G.*VEfact;
for k=1:3
a(k)=S(k+1);
W(k)=S(k+4);
z(k)=S(k+7);
end
G0=S(1);
for k=1:length(w)
Km(k)=(G0.*(1.+sum(a).*sum((((w(k).^4+ (4.*z.^2-1).*W.^2.*w(k).^2)./(w(k).^4+2.*(2.*z.^2-1).*W.^2.*w(k).^2+W.^4))./G1(k)-1)))).^2+...
(((G0.*(sum(a)*sum((2.*z.*w(k).*W.^3)./((w(k).^2-W.^2).^2+(4.*z.^2.*w(k).^2.*W.^2)))))./G2(k)-1)).^2;
end
end
The Complex modulus (experimental data) is to be obtained by the following relation: s0=[s0=[E .131005 .6105 .04101 4 4 4 188.5 1368 5702.1]; function [KSConc]=Modcomplex(w,j,G,Lfact) dataexp; % Calculation of complex modulus Ksw Kswcomp=zeros(1,length(w)); for j = 1:length(w) % et(j) = et(j) + 0.1; Kswcomp(j) = G1(j).*(1.+Lfact(j).*1i); end KswcompR=real(Kswcomp); KswcompI=imag(Kswcomp); KSConc=(KswcompR+KswcompI);
And I want to find the parameters by using fsolve, but I want to define my stopping criteria, with "e"... This is just part of my script file to run the minimization
for Iter=1:MaxIter options=optimset('Display','Iter','Algorithm','Levenberg-Marquardt','TolFun',1E-30,'TolX',1E-18,'MaxFunEvals',8000,'MaxIter',700); [S(Iter),fval(Iter)]=fsolve(@CM,s0,options); s0=S(Iter); Km(Iter)=CM(S,w,a,W,z); err(Iter)=(KSConc(Iter)-Km(Iter))./KSConc(Iter); e(Iter)=err(Iter).*err(Iter)'; if e<8e-5 break
G0=S(1);%z([7 8 9])=s0([7 8 9]); for i=1:3 a(i)=S(i+1); W(i)=S(i+4); z(i)=S(i+7); end
for k=1:length(w) g1(k)=G0+G0.*(sum(a).*sum(((w(k).^4+(4.*z.^2-1).*W.^2.*w(k).^2)./((w(k).^4+(2.*(2.*z.^2-1).*(W.^2.*w(k).^2))+W.^4)))));%.^2)+w(k).^4)))))); g2(k)=G0.*(sum(a).*sum((2.*z.*w(k).*W.^3)./((w(k).^2-W.^2).^2+(4.*z.^2.*w(k).^2.*W.^2)))); end
I still can get the parameters... I tried first to use fsolve without iterations.. but without good results.. and now I came up with the idea of using the error "e" to trigger the stopping criteria ... but .. still can´t figure it out why i can´t get it ... Any ideas guys ? .. thanks in advance..

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!