필터 지우기
필터 지우기

Finding solutions of a transcendental function

조회 수: 2 (최근 30일)
Denikka Brent
Denikka Brent 2018년 11월 4일
댓글: Denikka Brent 2018년 11월 4일
I have a function:
cos(wbar)-(IT.*wbar.*sin(wbar))==0
I am trying to propose this in a graphical manner by finding the two lowest solutions of this function. The graph will be IT vs wbar where IT is a vector of 0 to 5.
Any help on this?

채택된 답변

John D'Errico
John D'Errico 2018년 11월 4일
편집: John D'Errico 2018년 11월 4일
What have you tried? If nothing, then why not?
First, create IT.
n = 100;
IT = linspace(0,5,n);
Initialize wbar. Use NaNs, so you know what has been done so far.
wbar = NaN(n,2);
Thus, two solutions for each element of IT.
Now it is just a loop, over the elements of IT. Note that for IT == 0, the first two solutions must be just pi/2 and3*pi/2. Because then the problem reduces to cos(wbar) == 0.
wbar(1,:) = [pi/2,3*pi/2];
But now, each value of IT is only slightly different from the last one. So the next pair of solutions must also be close to the last. Just loop.
for i=2:n
% at each step, just create a new function handle,
% encapsulating the current value for IT(i).
fun = @(w) cos(w) - IT(i)*sin(w);
wbar(i,1) = fzero(fun,wbar(i-1,1));
wbar(i,2) = fzero(fun,wbar(i-1,2));
end
plot(IT,wbar,'-')
grid on
Now, you can hand this in for your homework assignment, which would make it fairly clear that you got the code from someone online, or you can make some effort. But that would be your decision to make. So why not use some ideas from what I wrote here, then making an effort to write it on your own?
  댓글 수: 1
Denikka Brent
Denikka Brent 2018년 11월 4일
Thank you. I followed this and understood. I was so close to solving this but got an error when using fzero. I believe because I didn't initialize wbar.
Thank you

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by