Clear Filters
Clear Filters

Finding solutions of a transcendental function

2 views (last 30 days)
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?

Accepted Answer

John D'Errico
John D'Errico on 4 Nov 2018
Edited: John D'Errico on 4 Nov 2018
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 Comment
Denikka Brent
Denikka Brent on 4 Nov 2018
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

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!