|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| x1 = 1;
|
| x2 = 1;
|
| tilp = 1/RHO;
|
| hatyp = exp(G-meanB*P);
|
| haty = hatyp;
|
| rep = (1+tilp)/tilp*hatyp;
|
| logq = log(1/rep);
|
| c1 = RHO/(1+RHO);
|
| c2 = c1;
|
| logu1 = (RHO*log(c1)+log(1-c1)+log(rep))/RHO;
|
| u1 = exp(logu1);
|
| logu2 = (RHO*log(c2)+log(1-c2)+log(rep))/RHO;
|
| u2 = exp(logu2);
|
| f1 = (rep*u1);
|
| f2 = (rep*u2);
|
|
|
| k1 = MU;
|
|
|
| tila1 = k1*(1+tilp);
|
|
|
| state0 = tila1;
|
| c0 = state0;
|
|
|
| derivs0 = [f1;f2;x1;x2;logq];
|
|
|
| derivs1 = zeros(model.n_f,model.n_x);
|
| derivs2 = zeros(model.n_f,model.n_x^2);
|
| derivs3 = zeros(model.n_f,model.n_x^3);
|
| derivs4 = zeros(model.n_f,model.n_x^4);
|
|
|
| if order==1
|
| [ initial_guess ] = derivs2coeffs( model,derivs0,derivs1 );
|
| elseif order==2
|
| [ initial_guess ] = derivs2coeffs( model,derivs0,derivs1,derivs2);
|
| elseif order==3
|
| [ initial_guess ] = derivs2coeffs( model,derivs0,derivs1,derivs2,derivs3 );
|
| elseif order==4
|
| [ initial_guess ] = derivs2coeffs( model,derivs0,derivs1,derivs2,derivs3,derivs4 );
|
| end
|
|
|
|
|
|
|
| [coeffs,model] = tpsolve(initial_guess,state0,model,params,c0,nodes,weights,tolX,tolF,maxiter,OPTIONS);
|
|
|
|
|
|
|
| solve = 1;
|
| stop = 0;
|
| t = 0;
|
| xt = state0;
|
| while stop==0
|
| t = t+1;
|
|
|
| [R,g,nPhi] = residual(coeffs,xt,params,c0,nodes,weights);
|
|
|
|
|
| if norm(R(:))>testF && solve==1
|
| t
|
| [coeffs] = tpsolve(coeffs,xt,model,params,c0,nodes,weights,tolX,tolF,maxiter,OPTIONS);
|
|
|
|
|
| [R,g,nPhi] = residual(coeffs,xt,params,c0,nodes,weights);
|
| end
|
|
|
| newxt = nPhi(:,disaster(t+1));
|
|
|
| if t>=10
|
| if max(abs(newxt-xt))<1e-7
|
| stop = 1;
|
| state0 = xt;
|
| coeffs0 = coeffs;
|
| end
|
| end
|
| xt = newxt;
|
| end
|
|
|
|
|