ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   reference a function (https://www.excelbanter.com/excel-worksheet-functions/77666-reference-function.html)

Bill Brehm

reference a function
 
Can I do something like this?

A B
1 =F(A1)
2 =F(A2)
3 =F(A3)
4 etc
5
6
7
8
9
10

and define a function in a cell called F, say maybe =sin(X)? This would give
me the ability to plot any function I can put in a cell.



Ardus Petus

reference a function
 
You will have to calulate the various functions in separate columns, then
use INDIRECT to reference the desired column.
See example: http://cjoint.com/?dqi70Wzv3V

HTH
--
AP

"Bill Brehm " <<don't want any spam a écrit dans le message de
...
Can I do something like this?

A B
1 =F(A1)
2 =F(A2)
3 =F(A3)
4 etc
5
6
7
8
9
10

and define a function in a cell called F, say maybe =sin(X)? This would

give
me the ability to plot any function I can put in a cell.





Herbert Seidenberg

reference a function
 
=CHOOSE(my_func,SIN(table),COS(table),TAN(table))
Select which function you want by setting
a cell named my_func to 1, 2 or 3 (max is 29).


Bill Brehm

reference a function
 
What do you mean by 'table' here? is it referring to Ardus Petus'
suggestion?

I was trying to look for a way to put a perhaps complicated function in only
one cell rather than in every cell in the range covered by the range of
arguments. I know I can do it with VB but looking for a way to do it on the
spreadsheet only.

Could array formulas be of any help?


"Herbert Seidenberg" wrote in message
oups.com...
=CHOOSE(my_func,SIN(table),COS(table),TAN(table))
Select which function you want by setting
a cell named my_func to 1, 2 or 3 (max is 29).




Harlan Grove

reference a function
 
Bill Brehm wrote...
Can I do something like this?

A B
1 =F(A1)
2 =F(A2)
3 =F(A3)
4 etc

....
and define a function in a cell called F, say maybe =sin(X)? This would give
me the ability to plot any function I can put in a cell.


The closest would be a udf like

Function F(a As Variant) As Variant
Dim fcn As String
Application.Volatile True
fcn = Evaluate("_F")
fcn = Replace(fcn, "$$", CStr(a))
F = Evaluate(fcn)
End Function

where _F would be a defined name referring to the actual function you
wanted to use, and $$ would be the token representing the argument to
F(). Note: you can't have both a udf named F and a defined name named F.


Herbert Seidenberg

reference a function
 
Assuming your data looks like this:
table results
0.00 0.00
0.15 0.15
0.31 0.30
0.46 0.44
.... ...
5.98 -0.30
6.13 -0.15
6.28 0.00

my_func
1

Table is the named range of numbers from 0.00 to 6.28
Select these numbers and
Insert Name Define Names in Workbook table
In the same manner, give the cell with the 1 the name my_func
Fill the <results column with the formula given in the previous post.
The column <results will now display the sine terms.
You can now plot the first column (radians) vs the second (x y plot).
To display the cosine, type in 2 in the my_func cell.
Now let's add an arbitrary fourth function, a quadratic.
Add Quad to the formula:
=CHOOSE(my_func,SIN(table),COS(table),TAN(table),Q uad)
Add this name to Names in Workbook Quad
Refers to =0.58*table^2-1.78*table+2.34
Type 4 into my_func and the quadratic curve will appear in your graph.



All times are GMT +1. The time now is 11:23 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com