![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/194299/image.jpeg)
Finding solutions of a transcendental function
1 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/194299/image.jpeg)
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?
更多回答(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!