Is there a way to accelerate the fsolve function, with the least lost of precision possible. In:
beta(n+1)=fsolve(F,beta(n))

6 件のコメント

Andrew Newell
Andrew Newell 2011 年 6 月 17 日
Why are you re-solving the same problem? If beta(1) is your initial guess, beta(2) should already be accurate to the default tolerance. Perhaps you really want to reduce the tolerance?
Sean de Wolski
Sean de Wolski 2011 年 6 月 17 日
Unless F is dependent on persistent variables.
Liber-T
Liber-T 2011 年 6 月 20 日
It is because my beta(n+1) is used to solve an ODE, that give us some number we enter in a matrix, than we the det of the matrix give us the Function F, and we continue until beta(n+1)=beta(n).
Sean de Wolski
Sean de Wolski 2011 年 6 月 20 日
Why don't you show us some of the code in F to see if that can be further optimized.
Liber-T
Liber-T 2011 年 6 月 20 日
F=@(x)10000000000000*det([0 besselj(0,(sqrt(Ko^2*Ed-(x)^2))*b) (i*bessely(0,sqrt((Ko^2*Ed-(x)^2))*b)+besselj(0,sqrt((Ko^2*Ed-(x)^2))*b)) -(i*bessely(0,sqrt((Ko^2-(x)^2))*b)+besselj(0,sqrt((Ko^2-(x)^2))*b));y(length(t),1) -besselj(0,(sqrt(Ko^2*Ed-(x)^2))*a) -(i*bessely(0,sqrt((Ko^2*Ed-(x)^2))*a)+besselj(0,sqrt((Ko^2*Ed-(x)^2))*a)) 0;0 -Ed*besselj(1,(sqrt(Ko^2*Ed-(x)^2))*b)/((sqrt(Ko^2*Ed-(x)^2))) -Ed*(i*bessely(1,sqrt((Ko^2*Ed-(x)^2))*b)+besselj(1,sqrt((Ko^2*Ed-(x)^2))*b))/((sqrt(Ko^2*Ed-(x)^2))) (i*bessely(1,sqrt((Ko^2-(x)^2))*b)+besselj(1,sqrt((Ko^2-(x)^2))*b))/((sqrt(Ko^2-(x)^2)));-(1-((e^2*ne0*besselj(0,mu1)/(me*Eo))/(omega*(omega-i*v))))*-y(length(t),2)/(((Ko^2*(1-((e^2*ne0*besselj(0,mu1)/(me*Eo))/(omega*(omega-i*v))))-(x)^2))) Ed*besselj(1,(sqrt(Ko^2*Ed-(x)^2))*a)/((sqrt(Ko^2*Ed-(x)^2))) Ed*(i*bessely(1,sqrt((Ko^2*Ed-(x)^2))*a)+besselj(1,sqrt((Ko^2*Ed-(x)^2))*a))/((sqrt(Ko^2*Ed-(x)^2))) 0]);
Liber-T
Liber-T 2011 年 6 月 20 日
s=0.1
t=0.001
f=200000000
%a=0.013;
%b=0.015;
%Ed=4.52;
omega=f*2*pi;
%v/omega=t
v=t*omega;
omegap=omega/s;
Eo=8.85418782*10^-12;
muo=1.25663706*10^-6;
Ko=sqrt((omega^2)*Eo*muo);
Ep=1-((omegap^2)/(omega*(omega-i*v)));
The answer here is 8.4049+0.0038*i

サインインしてコメントする。

 採用された回答

Sean de Wolski
Sean de Wolski 2011 年 6 月 17 日

0 投票

preallocate beta
beta = zeros(nmax+1,1);
beta(1) = beta_of_1;
for ii = 1:nmax
beta(ii+1) = fsolve(F,beta(ii));
end
EDIT more stuff:
You calculate:
  • 'sqrt((Ko^2-(x)^2))*b': 4x
  • 'sqrt((Ko^2*Ed-(x)^2))*a': 4x
  • the bessel functions multiple times a pop.
Turn your function handle into a function. Make each of these calculations once, then use them multiple times.

1 件のコメント

Liber-T
Liber-T 2011 年 6 月 17 日
Thnks, but I already know that trick, is there something else for fsolve?

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2011 年 6 月 17 日

0 投票

fsolve() can be much faster if you can constrain the range to search in.

2 件のコメント

Liber-T
Liber-T 2011 年 6 月 17 日
how do I constrain the range
Walter Roberson
Walter Roberson 2011 年 6 月 20 日
Sorry it turns out that fsolve() has no way of constraining ranges. fzero() can operate over an interval, if your function has only one independent variable.

サインインしてコメントする。

カテゴリ

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by