Understand fsolve in matlab?

조회 수: 8 (최근 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 CenterFile Exchange에서 Solver 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