fsolve with independent functions
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello, guys.
I've got some questions about 'fsolve'. The situation is following.
There is function handle matrix and its element function is independent each other. The reason why I put the functions into elements in the matrix is only I want to avoid very slow for-loop. In addition... Due to different output according to different x0, I duplicated function handle and made x0 matrix of different values for investigating multiple solutions.
In short, I used fsolve on the matrix of the independent functions.
The problem is that fsolve judges the state on results (w.r.t exitflag) integrally. 'Equation solved' message was displayed if every single (not partial) element equation was solved. So exitflag is always a single value, not a matrix. To make matters worse, there is no case of exitflag=-3 in R2012a.
I think there might be no solution in some elements as specfic x0 elements. In the case, I would only ignore them. (I don't wanna obsess that.) Could I get the results with exitflag matrix of independent elements?
eplasmafre=[4.7176e+12 4.2953e+12 3.5814e+12;2.5148e+12 1.7696e+10 5.2964e+12];
vthe=[1.6477e+06 1.6477e+06 1.6477e+06;1.6477e+06 1.6477e+06 1.6477e+06];
[meshx,meshy]=size(eplasmafre);LightVel=3e8;RFangFrequency=2*pi*13.56*1e6;
ScanDetail=[1 4 7];ScanDetailNum=length(ScanDetail);
ScanOrder=3:9;ScanOrderNum=length(ScanOrder);
ScansetNum=ScanDetailNum.*ScanOrderNum;Scanset=(reshape((ScanDetail'*(10.^(ScanOrder))),1,ScansetNum))';
eplasmafreScan=repmat(eplasmafre,[ScansetNum,1]);vtheScan=repmat(vthe,[ScansetNum,1]);
ScansetScan=sort(repmat(Scanset,meshx,meshy));
FtnforStocFre=@(Xfre)(1e8.*((4.*((LightVel./eplasmafreScan).*sqrt(2.*(1+((Xfre.^2)./(RFangFrequency.^2)))./(1+sqrt(1+((Xfre.^2)./(RFangFrequency.^2))))))./vtheScan).*((1./pi).*((exp(4.*(((LightVel./eplasmafreScan).*sqrt(2.*(1+((Xfre.^2)./(RFangFrequency.^2)))./(1+sqrt(1+((Xfre.^2)./(RFangFrequency.^2)))))).^2).*(RFangFrequency.^2)./(pi.*(vtheScan.^2))).*(1+(4.*(((LightVel./eplasmafreScan).*sqrt(2.*(1+((Xfre.^2)./(RFangFrequency.^2)))./(1+sqrt(1+((Xfre.^2)./(RFangFrequency.^2)))))).^2).*(RFangFrequency.^2)./(pi.*(vtheScan.^2)))).*expint((4.*(((LightVel./eplasmafreScan).*sqrt(2.*(1+((Xfre.^2)./(RFangFrequency.^2)))./(1+sqrt(1+((Xfre.^2)./(RFangFrequency.^2)))))).^2).*(RFangFrequency.^2)./(pi.*(vtheScan.^2)))))-1))-Xfre./((Xfre.^2)+(RFangFrequency.^2))));
options=optimset('Display','iter','TolFun',1e-20,'PlotFcns',@optimplotfval);
[solmat,~,exitflag,output]=fsolve(FtnforStocFre,ScansetScan,options);
1 commentaire
Walter Roberson
le 18 Juin 2012
Please consider adding some blank lines in the code, as everything just runs together.
Réponse acceptée
Alan Weiss
le 18 Juin 2012
I believe that your best course of action is to do the loop, one-dimensional problems. When fsolve addresses an N-dimensional problem, internally it estimates an approximate Hessian N-by-N matrix (well, it might not really do an N^2 matrix, but it does look at a larger problem). You can help it by giving it a Jacobian sparsity pattern.
But because you believe some of your 1-D problems are not soluble, and you want to know which ones, bite the bullet and just do the loop. You might be surprised how well it works.
Also, do not give a TolFun (or other tolerance) of less than eps ~ 2e-16. I would not give a tolerance of less than 1e-14 without a very good reason.
Alan Weiss
MATLAB mathematical toolbox documentation
2 commentaires
Alan Weiss
le 20 Juin 2012
I am not sure that I understand you. You cannot solve anything when you have a NaN in your initial value. The FunValCheck option exists to warn you about the existence of NaN in your iterations. Once a NaN creeps into your calculation, Optimization Toolbox solvers cannot proceed.
In your loop you can check if any NaN appear in an initial value, and skip those points.
But I feel I did not address your problem correctly. Please ask again if I missed the point.
Alan Weiss
MATLAB mathematical toolbox documentation
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Solver Outputs and Iterative Display dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!