Which solver to use? I cannot get an answer, though I know there is one.

1 回表示 (過去 30 日間)
aaron pung
aaron pung 2012 年 8 月 23 日
Greetings, I am looking to solve a nonlinear equation for a single variable. I have tried using MATLAB's 'solve' function, but it cannot find an answer. I know there is an answer, because I've plotted the left and right hand side, and there is an intersection point. Help? My code is as follows:
clear all;
clc;
close all;
micrometers = 1;
nanometers = micrometers / 1000;
degrees = pi/180;
eps1 = 2.5; % Permittivity, superstrate
epsg = 3; % Permittivity, grating
eps3 = 2.5; % Permittivity, substrate
theta = 0; % [deg.]
period = 1000 * nanometers; % Grating period
gthick = 1000 * nanometers; % Grating thickness
ido = 1; % diffractive order
pol = 'TE';
syms L
kwv = 2*pi/L;
Bi = ((2*pi/L)*(sqrt(epsg)*sin(theta*degrees)-ido*L/period));
ki = (epsg*kwv^2-Bi^2)^(1/2);
gi = (Bi^2-eps1*kwv^2)^(1/2);
di = (Bi^2-eps3*kwv^2)^(1/2);
lhs = tan(ki*gthick);
rhs = ((ki*(gi+di))/(ki^2-gi*di));
solve('lhs = rhs','L')
I get an answer of: Warning: Explicit solution could not be found. > In solve at 81 In Resonance_Calculator at 51
ans =
[ empty sym ]
If you plot LHS and RHS against each other, the intersection is around 1.670

採用された回答

Matt Fig
Matt Fig 2012 年 8 月 23 日
編集済み: Matt Fig 2012 年 8 月 23 日
Use:
ROOT = solve(lhs-rhs,'L');
There are other roots. You might just want to use FZERO:
fzero(@(x) subs(lhs,x)-subs(rhs,x),1.68)
fzero(@(x) subs(lhs,x)-subs(rhs,x),1.65)

その他の回答 (1 件)

Babak
Babak 2012 年 8 月 23 日
編集済み: Babak 2012 年 8 月 23 日
It seems that in yoru problem you ahve numerical value for all the variables and want to find L.
To do so, I don't recommend using the Symbolic Math Toolbox, but use the Optimization Toolbox.
Use fsolve() instead if you have MATLAB Optimization Toolbox License.
  1 件のコメント
Babak
Babak 2012 年 8 月 23 日
Type
help fsolve
in MATLAB Command window to see if you have it or not.

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

カテゴリ

Help Center および File ExchangeNumbers and Precision についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by