Creating a Function with Changing Variable Values for Precise Results

  • Thread starter hynpf
  • Start date
  • Tags
    Function
In summary, the function hypothetically takes the form f(x)=e^{-ax}, where a is a real number. It is possible to plot this function against [itex]\ln f(x)[/tex] in a spreadsheet, and to find a through linear regression.
  • #1
hynpf
2
0
Hi,

I'm trying to come up with a function, but I have no idea how.

Here's my idea of f(x):


f(5000) = 0.07
f(1000) = 0.25
f(900) = 0.28
f(700) = 0.3
f(500) = 0.5
f(200) = 0.8
f(100) = 0.9
f(50) = 0.97
f(1) = 0.99
f(0.5) = 0.999

where 0 < f(x) < 1

as f(x) approaches 0/1, the change becomes less and less noticeable, and becomes closer and closer to 0/1 but never become 0/1.

Thanks!
 
Last edited:
Physics news on Phys.org
  • #2
Thanks for the input.

I edited my post right before you posted, so here's a summary of characteristics:

f(x) can only be a positive real number between 0 and 1 exclusive.
x can be between 0 exclusive and infinite, but I want f(500) to be around 0.5, and I don't really care what f(x) will be after x = 500.

I don't need a precise function that fits all my sample values; those are just to illustrate what kind of curve the function takes. As long as it satisfies these conditions, I can take any function.

I'm no mathmatician, so I hope I explained this well..
 
  • #3
Looks very roughly exponential, of the form [tex]f(x)=e^{-ax}[/tex], a is some real number. You could graph x against [itex]\ln f(x)[/tex] in a spreadsheet like Excel or OpenOffice, and do a linear regression to find a.
 
Last edited by a moderator:
  • #4
rachmaninoff said:
You could graph x against [itex]\ln f(x)[/tex] in a spreadsheet like Excel or OpenOffice, and do a linear regression to find a.
If you put the data into Excel and graph the points (use the wizard); you can right-click on any of the data points and select Insert Trendline. In the Trendline dialog box, first click on its Type tab and select exponential or power, then go to Options tab and check "Display equation" and "Display R-squared" boxes. You can copy and paste the same graph over and over, then use different functional forms in each. You might want to select the functional form that maximizes the R-squared.
 
  • #5
0/1 would be 0.
 
  • #6
matt grime said:
0/1 would be 0.

He was using incorrect notation to describe the point [tex]\left( 0, 1 \right) \in \mathbb{R}^2[/tex].
 
  • #7
I would suggest perhaps an inverse tan curve, centred at x=500 and offset by an appropriate amount.

Claude.
 

FAQ: Creating a Function with Changing Variable Values for Precise Results

What is a function?

A function is a block of code that performs a specific task or set of tasks. It can take in inputs, called parameters, and return an output based on those parameters.

How do I come up with a function?

To come up with a function, you first need to identify the task or problem that needs to be solved. Then, think about the inputs or parameters that are needed to solve the problem. Finally, write the code that will perform the necessary steps and return the desired output.

What are the key components of a function?

The key components of a function include the function name, parameters (if any), and the function body. The function name is used to call the function, the parameters are the inputs that the function takes in, and the function body contains the code that performs the desired task.

Can a function have multiple outputs?

Yes, a function can have multiple outputs. This can be achieved by using the return statement to return multiple values, or by using global variables to store and access multiple outputs within the function.

How do I test and troubleshoot my function?

To test and troubleshoot a function, you can use various methods such as manually tracing through the code, using a debugger, or writing test cases to check the function's outputs. If there are errors or unexpected results, you can use debugging techniques to identify and fix the issue.

Back
Top