Error using fzero function

17 ビュー (過去 30 日間)
Simon Kreibich
Simon Kreibich 2016 年 1 月 19 日
編集済み: Matt J 2016 年 1 月 19 日
Hi guys,
I'm trying to use fzero to find the root of my function. It's nonlinear. But I'm getting this Error:
Error using fzero (line) FUN must be a function, a valid string expression, or an inline function object.
y = -0.6:0.001:0.6;
z = 0.1;
solutionsofthefunction = arrayfun(@(x) functionname(y, x), z);
fun = arrayfun(@(x)theta_delta_plot(z, x), y);
x0 = 0;
x = fzero(fun, x0)
can anyone give me a hint what I'm doing wrong?

採用された回答

Matt J
Matt J 2016 年 1 月 19 日
編集済み: Matt J 2016 年 1 月 19 日
It looks like this is what you're really trying to do,
x = fzero( @(x)theta_delta_plot(z, x) , x0)
  3 件のコメント
Steven Lord
Steven Lord 2016 年 1 月 19 日
It's just displaying 4 decimal places. Use the FORMAT command to change how the numbers are displayed (it does NOT how the numbers are used in computations.)
Matt J
Matt J 2016 年 1 月 19 日
編集済み: Matt J 2016 年 1 月 19 日
Is it possible to get closer to my root? Right now it looks like this:
The dark blue asterisk is what fzero found? Looks pretty close to zero to me, but you could zoom the y-axis so that we could see better.
I don't understand what the cyan line is supposed to show. Presumably it is the linear interpolation that the plotter is making between your given points. If so, its distance from the asterisk is meaningless. Redo the plot with finer sampling in the neighborhood of the fzero solution, and tell us what the sampling is.

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

その他の回答 (1 件)

Roger Wohlwend
Roger Wohlwend 2016 年 1 月 19 日
As the error message says, fzero needs a function handle as first Input Argument. Your variable fun is a Vektor or a Matrix, if I am not mistaken. Your code is a bit confusing. The first four lines don't have anything to do with your Goal of finding the Zeros of your function.
  2 件のコメント
Simon Kreibich
Simon Kreibich 2016 年 1 月 19 日
編集済み: Simon Kreibich 2016 年 1 月 19 日
I have a function which takes 2 parameters: first value as theta (z), and the second one is a vektor (y). With this function I calculate the changes of theta for each value of the vektor y. So my output has the same size as the vektor y.
With the third line I'm computing the function with thoes inputs.
For fzero I need this function, but I don't know how to do it.
How can I prove this function of a root using fzero?
edit: the image shows the output of the vektor of the functions and are plotted with the vektor y
plot(output_vektor, y)
Roger Wohlwend
Roger Wohlwend 2016 年 1 月 19 日
Sorry, I still have no clue what you mean with your lines 2 and 3. Part of the Problem is the variable and function names. If you speak German, as I suspect, please formulate your Problem in German. Describe in Detail what you want to do.

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

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by