How to solve transcendental equations in matlab
조회 수: 31 (최근 30일)
이전 댓글 표시
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?
댓글 수: 5
Walter Roberson
2018년 6월 13일
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
2018년 6월 12일
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])
댓글 수: 8
Anton Semechko
2018년 6월 12일
편집: Walter Roberson
2018년 6월 12일
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
2018년 6월 12일
Here is modified version of the code and visualization of computed results:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/189576/image.jpeg)
% 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
추가 답변 (1개)
Walter Roberson
2018년 7월 30일
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!