I have constructed a curve fit "func" with the following line.
func=fit(x,y,'pchipinterp')
Now I want to use "func" inside an anonymous function as e.g
func2= @ (x,c) x-(c*x+x^2)/func(x)
Then I want to find the root of func2=0 using e.g FZERO as
c=2;
func3=@ (x) func2(x,c)
sol=fzero(func3,<interval>)
Could it be causing any trouble that i am using a cfit object inside the function "func2" ? My solution output is making me suspicious. Note that func2 is not the actual function i'm using but of a similar form.
Any help is much appreciated!
Best regards

1 件のコメント

Adam Danz
Adam Danz 2020 年 4 月 29 日
"I am not sure this is a correct way of doing it ..."
Doing what?
"...because the solution is not what at all what you would expect?"
What is the solution and what do you expect?
We obviously cannot run the code nor do we know what the solution is or what you expect the solution to be.

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

 採用された回答

Adam Danz
Adam Danz 2020 年 4 月 29 日

0 投票

My blind guess is that x or c is a vector in which case,
func2= @ (x,c) x-(c.*x+x.^2)./func(x)
% ^ ^ ^

4 件のコメント

Philip Croné
Philip Croné 2020 年 4 月 29 日
I am wondering whether or not you can use a cfit object the way I have tried to illustrate.
Best regards
Adam Danz
Adam Danz 2020 年 4 月 29 日
As long as the cfit obj is defined prior to the anonymous function, there are no problems with that. You can think of the cfit obj as a function. You're providing it with inputs and it produces outputs.
Whatever you're seeing that makes you suspicious, it's not because you're using a cfit obj within an anonymous function.
Adam Danz
Adam Danz 2020 年 4 月 29 日
編集済み: Adam Danz 2020 年 4 月 29 日
Whenever you have a suspicion, simplify the problem and test it with known inputs and outputs.
% Create a cfit object
f = fittype('a*x');
c = cfit(f,2); % This just multiplies x by 2
% Create anon function that uses the cfit obj
fun = @(a,x) c(x) + a; % multiply x by 2 and add a
% Test it with known inputs
fun(10,[2 4 6])
ans =
14 % 2*2 + 10
18 % 4*2 + 10
22 % 6*2 + 10
Philip Croné
Philip Croné 2020 年 4 月 29 日
Thank you!
Best regards

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeFit Postprocessing についてさらに検索

製品

リリース

R2017b

質問済み:

2020 年 4 月 29 日

編集済み:

2020 年 4 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by