Login [Register]
Don't have an account? Register now to chat, post, use our tools, and much more.
No I must say I did not test my code. I was in a hurry I only had a short time to get stuff done for the day. Also the First part of the code worked, and was also decently fast. The last code was supposed to take the equation of the line of LDER1Y which was the first Derivative and fine that derivative, or the 2nd derivative of the original function.

I am sure their are optimizations, which I will work on later. I just need it to work for now. I will think about how to get that to work.

hhmm. This may be an epic flail but 2 possibilities that might work. The former might work better than the latter.


Code:

//1.
For(C,-1X,Y+1,A
C->|LDER2X(1+dim(|LDER2X   
Nderiv(xyLineLDER1Y,C,B,H->|LDER2Y(1+dim(|LDER2Y   
End

//2.
|LDERI1X->Y3
//no that would not work. There is no X and therefore cannot be a derivative right...
Ok I thought of something that should work, since nDeriv clearly will not.
This is with the entire code.


Code:

Delvar B 
SetupUpEditor |LDER1X,|LDER1Y,|LDER2X,|LDER2Y,|LDER3X,|LDER3Y
0->dim(|LDER1X
0->dim(|LDER1Y
0->dim(|LDER2X
0->dim(|LDER2Y
0->dim(|LDER3X
0->dim(|LDER3Y
Input "FUNCTION",Str1 
Str->Equ(Str1.Y1 
Input "INCREMENT OF DERIVATIVE",A 
If A<.1   
Then 
.0001->H 
Else 
.001->H 
End 
Input "LEFT BOUND OF DOMAIN",Q
Input "RIGHT BOUND OF DOMAIN",R 
For(B,Q-1,R+1,A
B->|LDER1X(1+dim(|LDER1X 
Nderiv(Y1,X,B,H->|LDER1Y(1+dim(|LDER1Y 
End
//THis has changed from here
|LDER1X->|LDER2X
For(C,Q-1,R+1,A
(|LDER1Y(C-1)- |LDER1Y(C))/(|LDER1Y(C-1)-(|LDER1X(C->\LDER1X 
End
|LDER2X->|LDER3X
For(D,Q-1,R+1,A
(|LDER2Y(D-1)- |LDER2Y(D))/(|LDER2Y(D-1)-(|LDER2X(D->\LDER2X
End

//To here This _Should_ work.
StatsOn
Plot1(xyLine,|LDER1X,|LDER1Y,[dot]
Plot2(xyLIne,|LDER2X,|LDER2Y,[cross]
Plot3(xyLine,|LDER3X,|LDER3Y,[open dot]
DispGraph
Removed the if/then statement and used ans for setting list dimensions.


Code:

Delvar B 
SetupUpEditor |LDER1X,|LDER1Y,|LDER2X,|LDER2Y,|LDER3X,|LDER3Y
0
Ans->dim(|LDER1X
Ans->dim(|LDER1Y
Ans->dim(|LDER2X
Ans->dim(|LDER2Y
Ans->dim(|LDER3X
Ans->dim(|LDER3Y
Input "FUNCTION",Str1 
Str->Equ(Str1.Y1 
Input "INCREMENT OF DERIVATIVE",A 
10*(A<=.1)*.0001->H
Input "LEFT BOUND OF DOMAIN",Q
Input "RIGHT BOUND OF DOMAIN",R 
For(B,Q-1,R+1,A
B->|LDER1X(1+dim(|LDER1X 
Nderiv(Y1,X,B,H->|LDER1X(1+dim(|LDER1Y 
End 
//THis has changed from here
|LDER1X->|LDER2X
For(C,Q-1,R+1,A
(|LDER1Y(C-1)- |LDER1Y(C))/(|LDER1X(C-1)-(|LDER1X(C->\LDER2Y 
End 
|LDER2X->|LDER3X
For(D,Q-1,R+1,A
(|LDER2Y(D-1)- |LDER2Y(D))/(|LDER2X(D-1)-(|LDER2X(D->\LDER3Y 
End 

//To here This _Should_ work.
StatsOn 
Plot1(xyLine,|LDER1X,|LDER1Y,[dot] 
Plot2(xyLIne,|LDER2X,|LDER2Y,[cross]
Plot3(xyLine,|LDER3X,|LDER3Y,[open dot]
DispGraph
Oh right. I knew that. I was mostly making sure it would work. Then Optimize it. Thanks though.
Aes_Sedia5 wrote:
Oh right. I knew that. I was mostly making sure it would work. Then Optimize it. Thanks though.
Well, does it work? You can test yourself by running it with a program where you know the first, second, and third derivative, and seeing what happens.
Let's take this polynomial:

Code:
15*x^8 - 21*x^7 + 17*x^4 + 28*x^2

We'll call the coefficients c_i and the exponents e_i:

Code:
c_1 = 15   e_1 = 8
c_2 = -21  e_2 = 7
c_3 = 17   e_3 = 4
c_4 = 28   e_4 = 2

See how that maps back to our first expression? (Pay close attention, now.) For any general set of coefficients and exponents, the derivative (with respect to x) of

Code:
c_1*x^e_1 + c_2*x^e_2 + ... + c_n*x^e_n

is going to be

Code:
e_1*c_1*x^(e_1 - 1) + e_2*c_2*x^(e_2 - 1) + ... + e_n*c_n*x^(e_n - 1)

That is, each term will have its c_i multiplied by the respective e_i, together multiplied by x raised to the power of one less than the same e_i.

Applying this rule to our earlier set of c's and e's, we get:

Code:
e_1*c_1*x^(e_1 - 1) + e_2*c_2*x^(e_2 - 1) + e_3*c_3*x^(e_3 - 1) + e_4*c_4*x^(e_4 - 1)

=

Code:
(8)*(15)*x^((8) - 1) + (7)*(-21)*x^((7) - 1) + (4)*(17)*x^((4) - 1) + (2)*(28)*x^((2) - 1)

=

Code:
120x^7 + (-147)x^6 + 68x^3 + 56x^1

Which is the correct derivative of our polynomial.

We already know the "x^" and "+" pieces are never going to change. If we were to write a program, we'd be more interested in those dynamic components, c_i and e_i. We'll dissect those outright and group them into lists:

Code:
L_C = {c_1,c_2,c_3,c_4} = {15,-21,17,28}
L_E = {e_1,e_2,e_3,e_4} = {8,7,4,2}

Now, the challenge is to figure out the coefficients and exponents of the derivative using just these numbers. Again, we'll multiply each c_i and e_i together to form the new coefficient list, and we'll subtract one from each e_i to get the new exponents. From this, we should end up with the proper number components for our first derivative.

Here's the two-step process:

Code:
L_C*L_E = {15,-21,17,28}*{8,7,4,2} = {120,-147,68,56}
L_E - 1 = {7,6,3,1}

As proof, remember our derivative from earlier:

Code:
120x^7 + (-147)x^6 + 68x^3 + 56x^1

You may extend this to the nth derivative.
An excellent, well-written, and very thorough post, Weregoose, thanks for that. Aes_, you could then combine that with string manipulation functions to build yourself a symbolic Nth derivative, assuming that you haven't already been trying to do so.
KermMartian wrote:
Aes_, you could then combine that with string manipulation functions to build yourself a symbolic Nth derivative, assuming that you haven't already been trying to do so.
I sort of tried talking him out of it. One would have to apply strong regulations on basically anything and everything that the user might type, including minus signs, square/cube signs, implicit X^1 and 1*X, and otherwise spurious instances of the variable. One might as well beg the user to provide the relevant digits apart from their polynomial forms. In terms of practicability, a string of "#X^#+#X^#+..." is as much as I'd ever want to work with.

Nonetheless, we're designing a program to do just that.

I did mention for him to continue down the long and winding road for the sake of practice, but the premise of the program sure doesn't have it as a requirement.
So I am working with sub( and trying some new (some would say simple) Things. and they are not working right. I am remaking my MathPack with some more complex code. One of which is this.


Code:

Text(0,0,"AREA AND VOLUME AND SURFACE AREAS
//looking at it, I have no idea why I did not include the first text, but this is the way the code is.
//L1 is the length of the strings that I need to seperate. Each one is added to the last. So L1(1) Is the first string.
//L1(2) is the second string. L`(2)-L2(1) is the length of that string.
{21,38,67,100,126,150,163,169,187}->L1
For(U,1,9
:Text(6U,0,sun("1.FIND FOR ARC-LENGTH2.FIND FOR CIRCLE3.RIGHT CIRCLE CONE4.RIGHT CIRCLE CYLINDER5.FIND FOR RECTANGLE PRISM6.FIND FOR RIGHT PYRAMID7.MORE SHAPES8.EXITMADE BY AES SEDIA5 CEMETECH",L1(U),L1(U)-L1(U-1)..


while working this, I may have just found my problem

Edit: nope I thought that having. L1(U)-L1(U-(U>1) would fix that, but it does not. I get a domain error right on the sub( line
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 12 of 12
» All times are GMT - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement