# Indexing functions?

8 messages
Open this post in threaded view
|

## Indexing functions?

 Hi; I have a function  depends on X and Y. I know X, thats an array so my function only depends on X But I want to create an "array of functions" which behave like f(1)= Y*1^2 f(2)=Y*2^2 f(3)=Y*3^2 . . . I should create different fuctions because every function will be postprossesed different way in further. clear clc x=1:1:10; for index=1:1:length(x);   f(index)=@(y) y*x(index).^2; end Is there a way to do this? -- Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html_______________________________________________ Help-octave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-octave
Open this post in threaded view
|

## Re: Indexing functions?

 On Mon, Oct 9, 2017 at 7:26 AM, denizyazgac wrote:Hi; I have a function  depends on X and Y. I know X, thats an array so my function only depends on X But I want to create an "array of functions" which behave like f(1)= Y*1^2 f(2)=Y*2^2 f(3)=Y*3^2 . . . I should create different fuctions because every function will be postprossesed different way in further. clear clc x=1:1:10; for index=1:1:length(x);   f(index)=@(y) y*x(index).^2; end Is there a way to do this? try thisclearx=1:1:10;for index=1:1:length(x);  f(index)={@(y) y*x(index).^2};endfeval(f{3}, 3 )this is not your final answer but it is a start _______________________________________________ Help-octave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-octave
Open this post in threaded view
|

## Re: Indexing functions?

 On Mon, Oct 9, 2017 at 8:00 AM, Doug Stewart wrote:On Mon, Oct 9, 2017 at 7:26 AM, denizyazgac wrote:Hi; I have a function  depends on X and Y. I know X, thats an array so my function only depends on X But I want to create an "array of functions" which behave like f(1)= Y*1^2 f(2)=Y*2^2 f(3)=Y*3^2 .-- clearfor index=1:10;  f(index)={@(y) y*index.^2};endfeval(f{3}, 1 )feval(f{10}, 2)DAS _______________________________________________ Help-octave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-octave
Open this post in threaded view
|

## Re: Indexing functions?

 In reply to this post by Doug Stewart-4 Thanks ! I also write as cell x=1:1:10; for index=1:1:length(x);  f{index}=@(y) y*x(index).^2; end But problem is, I always give some value to y. But I want to obtain functions like f(1)= Y*1^2 f(2)=Y*2^2 f(3)=Y*3^2 because I will also make some substraction from experimental data for *each f* and use that sum of differences for differential evaluation. So I should cover Y unknown till the end for optimisation. Main parameter is Y. So, there should be a cost function like x=1:1:10; for index=1:1:length(x);  f{index}=@(y) y*x(index).^2; end x=1:1:10; for jindex=1:1:length(x); cost_fun_array{jindex}=@(Y) abs(*f{jindex}*-exp_data(jindex)) %%But I can not call f{jindex} beacause Octave push me to give a value to Y; in that case I can not carry on optimisation cost_fun=sum(cost_fun_array) -- Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html_______________________________________________ Help-octave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-octave
Open this post in threaded view
|

## Re: Indexing functions?

 On Mon, Oct 9, 2017 at 8:38 AM, denizyazgac wrote:Thanks ! I also write as cell x=1:1:10; for index=1:1:length(x);  f{index}=@(y) y*x(index).^2; end But problem is, I always give some value to y. But I want to obtain functions like f(1)= Y*1^2 f(2)=Y*2^2 f(3)=Y*3^2 because I will also make some substraction from experimental data for *each f* and use that sum of differences for differential evaluation. So I should cover Y unknown till the end for optimisation. Main parameter is Y. So, there should be a cost function like x=1:1:10; for index=1:1:length(x);  f{index}=@(y) y*x(index).^2; end x=1:1:10; for jindex=1:1:length(x); cost_fun_array{jindex}=@(Y) abs(*f{jindex}*-exp_data(jindex)) %%But I can not call f{jindex} beacause Octave push me to give a value to Y; in that case I can not carry on optimisation cost_fun=sum(cost_fun_array) What are you trying to do? tell us the overall picture of what you are doing.curve fitting?finding a formula?-- DAS _______________________________________________ Help-octave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-octave
Open this post in threaded view
|

## Re: Indexing functions?

 Okey; I try to make an optimisation with using DE I have a function which changes with two variable. One of them is frequency, other one is resistance for example: func=@(x,f)  x*f I have an experimental data of "func" in frequency domain and I try to back calculate x. So I have for example; f=[100,200,300]; exp_data=[200,400,600] as an experimental results. And I try to find best x which satisfies error_array=@(x,f) abs(func(x,f(index))-exp_data(index))^2; %error function for each frequency sum_error=@(x,f) sum(error_array(x,f)) % I try to minimize that function So I use sum_error for DE search. I hope thats clear. -- Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html_______________________________________________ Help-octave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-octave