Understand fsolve in matlab?

5 ビュー (過去 30 日間)
Hannah
Hannah 2014 年 11 月 22 日
コメント済み: Matt J 2014 年 11 月 23 日
Hi, I have an equation along the lines of f(x,k)=sinx-kx=0, and am told to use inputs k, to return x0(k). Is someone please able to explain how I could use fsolve, or any other method to find this. I am struggling to see how to input a k using this function. Thanks
  1 件のコメント
Matt J
Matt J 2014 年 11 月 23 日
So equivalently, you want to solve
sinc(x)=k
The equation has no solution for abs(k)>=1. For abs(k)<1, it will have multiple solutions. For k=0, it will have infinite solutions. Which ones do you want?

サインインしてコメントする。

回答 (1 件)

Star Strider
Star Strider 2014 年 11 月 22 日
I am not sure what you want to do, but this will get you started:
fn = @(x,k) sin(x) - k*x; % Define Function
k = 0.5; % Define ‘k’ For This Solution
X0 = 2; % Initial Estimate For ‘x’
x = fzero(@(x) fn(x,k), X0); % Solve for ‘x’
Note that the solution for ‘x’ depends also on ‘X0’.
Experiment with this to get the result you want.
  2 件のコメント
Hannah
Hannah 2014 年 11 月 22 日
what do i then input into the command window? im presuming i cant change k in the command window at all?
Star Strider
Star Strider 2014 年 11 月 22 日
You can change anything you like!
I would put this in a script instead of running it from the Command Window.
If you want to evaluate your function for a range of ‘k’ values, a loop is an option.
For example:
fn = @(x,k) sin(x) - k*x; % Define Function
k = 0.1:0.1:10; % Define A Range For ‘k’
for k1 = 1:length(k)
X0 = 2; % Initial Estimate For ‘x’
x(k1) = fzero(@(x) fn(x,k(k1)), X0); % Solve for ‘x’
end
The ‘x’ vector now has a solution for each value of ‘k’.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by