Erel B4X founder Staff member Licensed User Longtime User Jan 26, 2014 #1 Edit: Don't miss the bonus question in post #11. Back to high school quiz. In your code should be a sub with the following signature: Code: Copy Sub Func(x As Double) As Double The user implements this function. The user enters (directly in the code) any math function they like. The quiz is to draw the math function. Some examples (the red graph will be explained soon): Code: Copy Sub Func(x As Double) As Double Return x End Sub Code: Copy Return x * x Code: Copy Return Sin(x) * Cos(x) Code: Copy Return Logarithm (x, cE) Code: Copy Return Abs(x) The recommended signature of the drawing sub should be: Code: Copy Sub Draw(MinX As Double, MaxX As Double, MinY As Double, MaxY As Double) As you have probably guessed the red graph is the function derivative. Note that the only "user" input is the implementation of the Func sub. 6 (out of 10) points - Correctly draw the function. 10 points - Correctly draw the function and its derivative. You can implement it in B4J or B4A. Last edited: Jan 26, 2014
Edit: Don't miss the bonus question in post #11. Back to high school quiz. In your code should be a sub with the following signature: Code: Copy Sub Func(x As Double) As Double The user implements this function. The user enters (directly in the code) any math function they like. The quiz is to draw the math function. Some examples (the red graph will be explained soon): Code: Copy Sub Func(x As Double) As Double Return x End Sub Code: Copy Return x * x Code: Copy Return Sin(x) * Cos(x) Code: Copy Return Logarithm (x, cE) Code: Copy Return Abs(x) The recommended signature of the drawing sub should be: Code: Copy Sub Draw(MinX As Double, MaxX As Double, MinY As Double, MaxY As Double) As you have probably guessed the red graph is the function derivative. Note that the only "user" input is the implementation of the Func sub. 6 (out of 10) points - Correctly draw the function. 10 points - Correctly draw the function and its derivative. You can implement it in B4J or B4A.
LucaMs Expert Licensed User Longtime User Jan 27, 2014 #21 All this was very interesting (but... how much am i a liar? ) Since I love the "booooo" and Unlike (I should put an "I Wish" for it) try to squeeze your excellent brains for this Last edited: Jan 27, 2014 Upvote 0
All this was very interesting (but... how much am i a liar? ) Since I love the "booooo" and Unlike (I should put an "I Wish" for it) try to squeeze your excellent brains for this
Erel B4X founder Staff member Licensed User Longtime User Jan 27, 2014 #22 All this was very interesting (but... how much am i a liar? ) Click to expand... I will explain again, the following 5 lines code outputs the values of the Sinus function. It should at least be surprising... Code: Copy Dim intervalX = 0.001, y = 0, dy = 1, x As Double For x = 0 To 2 * cPI Step intervalX Log(x & ": " & y) y = y + dy * intervalX dy = dy - y * intervalX Next Last edited: Jan 27, 2014 Upvote 0
All this was very interesting (but... how much am i a liar? ) Click to expand... I will explain again, the following 5 lines code outputs the values of the Sinus function. It should at least be surprising... Code: Copy Dim intervalX = 0.001, y = 0, dy = 1, x As Double For x = 0 To 2 * cPI Step intervalX Log(x & ": " & y) y = y + dy * intervalX dy = dy - y * intervalX Next
LucaMs Expert Licensed User Longtime User Jan 27, 2014 #23 Erel said: I will explain again, the following 6 lines code outputs the values of the Sinus function. It should at least be surprising... Code: Copy Dim intervalX = 0.01, y = 0, dy = 1 As Double For x = 0 To 2 * cPI Step intervalX dy = dy - y * intervalX y = y + dy * intervalX Log(x & ": " & y) Next Click to expand... I was kidding, of course. I have not read everything (the thread) well. But this your post means that I have something interesting to read. A moment: I read it Upvote 0
Erel said: I will explain again, the following 6 lines code outputs the values of the Sinus function. It should at least be surprising... Code: Copy Dim intervalX = 0.01, y = 0, dy = 1 As Double For x = 0 To 2 * cPI Step intervalX dy = dy - y * intervalX y = y + dy * intervalX Log(x & ": " & y) Next Click to expand... I was kidding, of course. I have not read everything (the thread) well. But this your post means that I have something interesting to read. A moment: I read it
Erel B4X founder Staff member Licensed User Longtime User Jan 27, 2014 #24 I was kidding too. Don't worry Upvote 0
LucaMs Expert Licensed User Longtime User Jan 27, 2014 #25 I'm sorry, but I can not understand what should surprise me (but that's because I'm not exactly an expert on Math Functions!). I did not write, jokingly, that "this is an interessant thread" because I am an expert, not at all (to tell the truth, to draw a circle remember that I had a problem with Step!) Personally I have no interest in this type of argument ("BOOOO, do not read it, then!" ) I have a bad way of joking; many people find it irritating. In fact I am one of the sweetest people on the Planet! One day I will tell you my whole story (probably not in the "Quiz" section ). I was joking and I really like the Quiz. I will attend the next Last edited: Jan 27, 2014 Upvote 0
I'm sorry, but I can not understand what should surprise me (but that's because I'm not exactly an expert on Math Functions!). I did not write, jokingly, that "this is an interessant thread" because I am an expert, not at all (to tell the truth, to draw a circle remember that I had a problem with Step!) Personally I have no interest in this type of argument ("BOOOO, do not read it, then!" ) I have a bad way of joking; many people find it irritating. In fact I am one of the sweetest people on the Planet! One day I will tell you my whole story (probably not in the "Quiz" section ). I was joking and I really like the Quiz. I will attend the next
mc73 Well-Known Member Licensed User Longtime User Jan 27, 2014 #26 Lucas, using tricks in coding is sometimes very important. For example I used the above sinus algorithm, in a old slot machine game, where I added an animation effect of vibrating elements. Since it was in assembly, I chose to avoid a 'straight' calc of sinus, since it would require Taylor's series and it could be less speedy. Nowadays machines are incredibly faster, still it's always great discovering and applying such tricks Upvote 0
Lucas, using tricks in coding is sometimes very important. For example I used the above sinus algorithm, in a old slot machine game, where I added an animation effect of vibrating elements. Since it was in assembly, I chose to avoid a 'straight' calc of sinus, since it would require Taylor's series and it could be less speedy. Nowadays machines are incredibly faster, still it's always great discovering and applying such tricks
LucaMs Expert Licensed User Longtime User Jan 27, 2014 #27 Sure, I agree that the algorithms can (almost always) be optimized. We want to say that I have always hated math functions? Upvote 0
Sure, I agree that the algorithms can (almost always) be optimized. We want to say that I have always hated math functions?