Indexing functions?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Indexing functions?

denizyazgac
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
Reply | Threaded
Open this post in threaded view
|

Re: Indexing functions?

Doug Stewart-4


On Mon, Oct 9, 2017 at 7:26 AM, denizyazgac <[hidden email]> 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 this
clear

x=1:1:10;
for index=1:1:length(x);
  f(index)={@(y) y*x(index).^2};
end

feval(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
Reply | Threaded
Open this post in threaded view
|

Re: Indexing functions?

Doug Stewart-4


On Mon, Oct 9, 2017 at 8:00 AM, Doug Stewart <[hidden email]> wrote:


On Mon, Oct 9, 2017 at 7:26 AM, denizyazgac <[hidden email]> 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
.


-- 



clear


for index=1:10;
  f(index)={@(y) y*index.^2};
end

feval(f{3}, 1 )

feval(f{10}, 2)
DAS


_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Indexing functions?

denizyazgac
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
Reply | Threaded
Open this post in threaded view
|

Re: Indexing functions?

Doug Stewart-4


On Mon, Oct 9, 2017 at 8:38 AM, denizyazgac <[hidden email]> 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
Reply | Threaded
Open this post in threaded view
|

Re: Indexing functions?

denizyazgac
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
Reply | Threaded
Open this post in threaded view
|

Re: Indexing functions?

Doug Stewart-4


On Mon, Oct 9, 2017 at 9:58 AM, denizyazgac <[hidden email]> wrote:
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.




did you read 

why not make a function that returns sum_error and then use one of the functions on that page?

function ret=plant(x,f)
...
ret=sum_error
end function



_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Indexing functions?

denizyazgac
I use sum, because I try to find x which best fits for all frequency range.
I should use global search technics because original function depends on 3
x, [x(1),x(2),x(3)] and one f. Function is highly nonlinear, there are some
local minima but I try to find global minima in search region.

Thanks



--
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