# How to solve transcendental equations in matlab

91 views (last 30 days)
alburary daniel on 12 Jun 2018
Answered: Walter Roberson on 30 Jul 2018
I am practicing solving transcendental equations in matlab I have the given equation and I want to solve for x
tan(((0.9)*pi/w)*sqrt(1.468^2-x.^2))- sqrt((x.^2-1.458^2))/(sqrt(1.468^2-x.^2))==0
plotting w varies from 1.55 to 5 I tried all day but I cannot find solution, I tried with fzero(fun,xo) without success any suggestion?

Walter Roberson on 12 Jun 2018
alburary daniel on 12 Jun 2018
A feel confuse because a will trying to solve problemas using newton rapson method
Walter Roberson on 13 Jun 2018
Do not close questions that have an Answer. The volunteers spent time responding to you, and their responses may help other people with similar questions.
I know that I spent about 2 hours investigating this myself, and I am disappointed that my contribution would just disappear as if I had never done the work.

Anton Semechko on 12 Jun 2018
This is a complex-valued function. Just from visual inspection, it is apparent that the real part of this function has infinitely many solutions. The imaginary part, however, appears to have a finite number of zeros. Are those the solutions you are looking for?
x=linspace(-2*pi,2*pi,1E4);
w=1.55;
f=tan(((0.9)*pi/w)*sqrt(1.468^2-x.^2)) - sqrt((x.^2-1.458^2))./(sqrt(1.468^2-x.^2));
figure('color','w')
plot(x,real(f))
hold on
plot(x,imag(f))
set(gca,'YLim',[-10 10])

alburary daniel on 12 Jun 2018
but in this case I want that x-axis will be W not b, so change the result rigth in the code? by the way what do Z? can you explain that sentences
Anton Semechko on 12 Jun 2018
If you want to plot w along horizontal axis, change
plot(Z(i),W(i),'.k','MarkerSize',20) to plot(W(i),Z(i),'.k','MarkerSize',20),
plot(Z,W,'-b') to plot(W,Z,'-b')
x- and y-labels would have to be modified accordingly.
Variable Z is a vector that contains solutions to f(x,w)=0, so that abs(f(Z(i),W(i)))<tol, where tol=1E-16. W is vector of w values that go from 1.5 to 5.
Anton Semechko on 12 Jun 2018
Here is modified version of the code and visualization of computed results: % Equation
a=0.9;
n1=1;
n2=1.5;
f=@(x,w) tan((a*pi/w)*sqrt(n2^2-x.^2)) - sqrt((x.^2-n1^2))./(sqrt(n2^2-x.^2));
% Look for zeros for w=[1.5 5]
W=linspace(1.5,5,1E2);
X=linspace(n1+1E-12,n2-1E-12,1E3);
Z=0.5*(n1+n2)*ones(size(W));
Opt=optimset('Display','off');
figure('color','w')
for i=1:numel(W)
% Initialize search
F=f(X,W(i));
[F_min,id]=min(abs(F));
Z(i)=X(id);
% Refine solution
f_i=@(x) f(x,W(i));
[Zi,Fi]=fzero(f_i,Z(i),Opt);
if abs(Fi)<abs(F_min), Z(i)=Zi; end
plot(W(i),Z(i),'.k','MarkerSize',20)
hold on
end
plot(W,Z,'-b')
xlabel('w','FontSize',25,'FontWeight','bold')
ylabel('b','FontSize',25,'FontWeight','bold')
set(gca,'FontSize',20)
grid on