91 views (last 30 days)

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?

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])

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

Sign in to comment.

Walter Roberson
on 30 Jul 2018

Stop closing your questions that people have already answered!!

We are not free private consultants: public questions and public answers are the price we "charges". We answer publicly as volunteers so that everyone can benefit. When you close questions after people have answered, then you are taking advantage of what you learned but you are grabbing it away to prevent anyone else from benefiting from the time and knowledge that other people have contributed.

Sign in to comment.

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 5 Comments

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/405170-how-to-solve-transcendental-equations-in-matlab#comment_577605

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/405170-how-to-solve-transcendental-equations-in-matlab#comment_577605

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/405170-how-to-solve-transcendental-equations-in-matlab#comment_577770

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/405170-how-to-solve-transcendental-equations-in-matlab#comment_577770

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/405170-how-to-solve-transcendental-equations-in-matlab#comment_577958

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/405170-how-to-solve-transcendental-equations-in-matlab#comment_577958

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/405170-how-to-solve-transcendental-equations-in-matlab#comment_578008

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/405170-how-to-solve-transcendental-equations-in-matlab#comment_578008

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/405170-how-to-solve-transcendental-equations-in-matlab#comment_578110

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/405170-how-to-solve-transcendental-equations-in-matlab#comment_578110

Sign in to comment.