Understand fsolve in matlab?

5 Ansichten (letzte 30 Tage)
Hannah
Hannah am 22 Nov. 2014
Kommentiert: Matt J am 23 Nov. 2014
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 Kommentar
Matt J
Matt J am 23 Nov. 2014
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?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Star Strider
Star Strider am 22 Nov. 2014
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 Kommentare
Hannah
Hannah am 22 Nov. 2014
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 am 22 Nov. 2014
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’.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by