Making a function that fulfills predetermined input and output pairs

BunnyWitch

New member
Joined
Sep 1, 2022
Messages
8
Hello. Sorry if this is in the wrong place, I don't really know. I do have a specific problem I want solved, but I'm also asking for a general guide on how to solve anything similar. Let's say I want a variable that will take any integer input, and output a number between 0 and 100. For my specific example, I want anything less than or equal to 3,125 to output a 0, 100,000 to output 50, and anything greater than or equal to 1,400,000 to output 100. What would that function look like, if possible, and if I wanted to make a similar function with different predetermined values, what should I do?
 
Since you have defined the outputs for a subset of inputs can't you simply (linearly) interpolate the outputs in the remaining intervals? You haven't specified whether the outputs must be integer, but if they are you can round the interpolation results to the nearest integer values.

The above is one approach, but this is not a unique solution. But a preferred solution might depend on other requirements which you might have but haven't stated explicitly.
 
I'm sorry, but could you tell me what interpolate means? And I'm sorry, integer isn't what I meant, rational inputs and outputs should work as well
 
Hello. Sorry if this is in the wrong place, I don't really know. I do have a specific problem I want solved, but I'm also asking for a general guide on how to solve anything similar. Let's say I want a variable that will take any integer input, and output a number between 0 and 100. For my specific example, I want anything less than or equal to 3,125 to output a 0, 100,000 to output 50, and anything greater than or equal to 1,400,000 to output 100. What would that function look like, if possible, and if I wanted to make a similar function with different predetermined values, what should I do?
What do you want the graph to look like? A set of lines? A smooth curve? A curve that may have sharp bends?

Do you know anything about the relationship between the input and out put other than three numbers for each? That is, what sort of reality should the function be approximating?
 
Well, now that I look at that, I assume it should be a curve instead. Sorry, I guess I misunderstood the wiki page.
 
The problem with your question is this.

If you specify n points, where n is finite, there are an infinite number of functions that will exactly fit those n points. It is in fact fairly trivial to find such a function.

If you have reason to believe that the function relating those points is of a specific type modified by random error, there is a technique to find the unmodified function.

So, with only three non-collinear points specified, we can say that there is no exact linear function involved, or that there is one exact quadratic function possible, or that there are an infinite number of possible other exact but non-linear functions involved, or that there are an infinite number of possible functions, including linear ones, involved but affected by a random variable. Lots of very different possibilities.

The best way to proceed is to gather more data and then to test various hypotheses. This is not a type of problem easy to solve.
 
The problem with your question is this.

If you specify n points, where n is finite, there are an infinite number of functions that will exactly fit those n points. It is in fact fairly trivial to find such a function.

If you have reason to believe that the function relating those points is of a specific type modified by random error, there is a technique to find the unmodified function.

So, with only three non-collinear points specified, we can say that there is no exact linear function involved, or that there is one exact quadratic function possible, or that there are an infinite number of possible other exact but non-linear functions involved, or that there are an infinite number of possible functions, including linear ones, involved but affected by a random variable. Lots of very different possibilities.

The best way to proceed is to gather more data and then to test various hypotheses. This is not a type of problem easy to solve.
Like this?1662762968343~2.png
Edit: This was meant to be in reply to Subhotosh Khan
 
Last edited:
The problem with your question is this.

If you specify n points, where n is finite, there are an infinite number of functions that will exactly fit those n points. It is in fact fairly trivial to find such a function.

If you have reason to believe that the function relating those points is of a specific type modified by random error, there is a technique to find the unmodified function.

So, with only three non-collinear points specified, we can say that there is no exact linear function involved, or that there is one exact quadratic function possible, or that there are an infinite number of possible other exact but non-linear functions involved, or that there are an infinite number of possible functions, including linear ones, involved but affected by a random variable. Lots of very different possibilities.

The best way to proceed is to gather more data and then to test various hypotheses. This is not a type of problem easy to solve.
One quadratic function?
 
It appears from your post#11 that you require any function that appears smooth that goes through the points. As JeffM says there are infinite ways of doing this mathematically.

This is what happens if you fit your 3 points to a quadratic...

graph1.png

There's a large amount of overshoot due to the high gradient of the first two points.

This is what happens if you take natural log of the x values before fitting to a quadratic f(z) and then plotting f( ln(x) )...
graph2.png

You say that you want a way to generate these curves yourself - but depending on how the 3 points change then you might need to do some "fiddling around" before obtaining a desired result. You'll probably have to graph your function and check it at the "desired points" and especially between the desired points to ensure the behaviour is acceptable.

Another option is using "bezier curves" (which are often used in computer vector graphics). These have control points that enable an artist to make smooth curves.

So that we can help further, what is your background? Where did you find this question (are you a student)? And by how much can the points vary? Any extra information that you can give would help us to give the most suitable advice.
 
I'm not a student, but I did just graduate high-school. As for where I got this equation... I play this game, with attacking and battle stats. This table is about how defense and attack are related. The only info I could find on it was a 3 part table. Assuming you are attacked by someone with 100,000 Attack, 3125 Defense or less will block 0% of the damage, 100,000 Defense will block 50% of the damage, and 1,400,000 Defense or more will block 100%. I couldn't find any kind of formula in the game or online, so I wanted to see if I could find a formula that could fill in the rest. But I'm not very good at math.
 
I don't really know how the math works, so I didn't know that there isn't going to be just one way for that to work. If that's the case then there's probably no way for me to find the specific equation used, so I guess that's it for this. Sorry for wasting your time and thank you for being patient with me.
 
I don't really know how the math works, so I didn't know that there isn't going to be just one way for that to work. If that's the case then there's probably no way for me to find the specific equation used, so I guess that's it for this. Sorry for wasting your time and thank you for being patient with me.
Perhaps (re) learning some math might be useful for your gaming skills? Having some knowledge of probability would also be a bonus. Please post again if you need help. Since you're not a student, here's the equation for the second graph in post#13...

Let z = ln(x)
If 3125 ≤ x ≤ 1400000 then the percentage is approx y=0.74027219*z^2 - 0.05285884*z - 47.51263365
 
I don't really know how the math works, so I didn't know that there isn't going to be just one way for that to work. If that's the case then there's probably no way for me to find the specific equation used, so I guess that's it for this. Sorry for wasting your time and thank you for being patient with me.
You are correct that there probably is no way for you to know for sure what equation to use, but you can find an equation that will give you a good approximation. I suspect a sigmoid will work.
 
Top