Is this function correct? (Not a homework Question)

In summary, the conversation involves the creation of three functions, f(x), g(x), and w(x), with specific equations. The values of these functions are then calculated for a given value of x, resulting in the correct answers. The conversation ends with a thank you message.
  • #1
QuantumPixel
7
1
I was bored and decide to make a function (yes, i am a bit weird). So I came up with this:

f(x)=2x+3
g(f)= f+2
w(g)=g2+3

x=2

f(2)=4+3
f(2)=7
g(7)=7+2
g(7)=9
w(9)=81+3
w(9)=82

Is those working outs correct or not? If it isn't could you tell me where i got it wrong?
 
Physics news on Phys.org
  • #2
As long as you mean g(f(x)) and w(g(f(x))), then you have the right answer
 
  • #3
Yes, what you have is correct. More generally, with f(x)= 2x+ 3, g(x)= x+ 2, and [itex]w(x)= x^2+ 3[/itex], [itex]g(f(x)= (2x+ 3)+ 2= 2x+ 5[/itex] and [itex]w(g(f(x)))= (2x+ 5)^2+ 3= 4x^2+ 20x+ 28[/itex].

Evaluating that at x= 2 gives 4(4)+ 20(2)+ 28= 16+ 40+ 28= 84.
 
  • #4
Gackhammer said:
As long as you mean g(f(x)) and w(g(f(x))), then you have the right answer

HallsofIvy said:
Yes, what you have is correct. More generally, with f(x)= 2x+ 3, g(x)= x+ 2, and [itex]w(x)= x^2+ 3[/itex], [itex]g(f(x)= (2x+ 3)+ 2= 2x+ 5[/itex] and [itex]w(g(f(x)))= (2x+ 5)^2+ 3= 4x^2+ 20x+ 28[/itex].

Evaluating that at x= 2 gives 4(4)+ 20(2)+ 28= 16+ 40+ 28= 84.

Thanks for your time on here! :-)

-QuantumPixel
 

1. Is there a specific method or process to determine if a function is correct?

Yes, there are several methods that can be used to determine if a function is correct. One common approach is to test the function with a variety of input values and compare the output to the expected results. It can also be helpful to check for edge cases and potential errors in the function's code.

2. How do I know if my function is efficient?

The efficiency of a function can be evaluated by analyzing its time and space complexity. This includes looking at the number of operations performed and the amount of memory used. Generally, a more efficient function will have a lower time and space complexity.

3. Can a function be correct but still produce unexpected results?

Yes, a function can be technically correct but still produce unexpected results. This can occur if the function is not handling all possible input values or if there are errors in the logic of the function. It is important to thoroughly test a function to ensure it is producing the desired results.

4. Is it necessary to document my function even if it is correct?

While documentation is not required for a function to be considered correct, it is highly recommended. Proper documentation can help others understand the purpose and functionality of the function, making it easier for them to use and maintain in the future.

5. What should I do if I am unsure if my function is correct?

If you are unsure about the correctness of your function, it is best to seek feedback from others. This can include asking for help from colleagues or consulting with a more experienced programmer. It can also be helpful to review the function's code and test it with different input values to identify any potential errors.

Similar threads

  • Calculus
Replies
6
Views
1K
Replies
2
Views
1K
Replies
3
Views
725
Replies
2
Views
960
  • Calculus
Replies
9
Views
2K
Replies
5
Views
1K
Replies
1
Views
956
Replies
36
Views
4K
Replies
3
Views
2K
Back
Top