Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Two questions regarding functions

Author
Message
Acronim
15
Years of Service
User Offline
Joined: 7th Dec 2008
Location:
Posted: 7th Dec 2008 17:05
Hi, I have a couple of questions. I guess some of them are already asked, but my internet is being stupid, and I do not wish to spend eternity looking around to see whether this has been asked before or not.

The questions all have to do with a simple program I am trying to write. It has little use, but it is good practice, I think.
The program is like this:
It finds the derivatives (and later anti-derivatives) of simple polynomial functions. That's it. Later, I want to expand it, but for now, it doesn't matter.

First question:

I have made a short do loop
In it, I use the input command, and store the data in a string task$.
Next, I want to go to a function that has the same name as the string task$, so I tried task$().
Say, I have a function (outside of the loop) called derive().
So if I'd input "derive", I want to go to the function called derive().

Obviously, this doesn't work, but is it possible to do this, and if so, could someone tell me how?


Second question:
(Maybe a bit confusing. I apologise for that)

Say, I have this code:

This is not what I really want.

The program first asks for the amount of terms in the polynomial, so that is the highest power of x plus one, for those who know what I'm talking about.

I want to find the symbolic derivative of the polynomial by deriving each term ((d/dx)ax^n=(nax^(n-1) for each term seperately).
So I want to use a for next loop, as above, but differently.
I want to have the constant multiple of each term, and store it somehow, so that I can write the entire derivative in one go later on.

So something like this:


But this of course does not store the value of a for each term, but simpy overwrites it.
How could I store every seperate value for a easily, and still be able to use them later on? (After the for next loop)


That is it for now, I am afraid I will be asking more later, but now I have to walk my dog, because he is starting to get desperate :p.

Thank in advance
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 7th Dec 2008 18:49
You can't call a function using a variable like that, unfortunately. The variable Derive and the function Derive() are completely seperate from each other.

You'd have to do something like this:



For your second question, try using an array. With an array you can store all the values the user inputs and then look back at them later with another for-next loop, for example:



Acronim
15
Years of Service
User Offline
Joined: 7th Dec 2008
Location:
Posted: 19th Dec 2008 13:19
Thanks!
About the first part...
I think I had had a short thought about an "if", but I was hoping to keep the main loop short and clean.
I guess that can still be done, but it seems useless to me (would be something like):

This seems to me like it could get confusing, but I'll see what I do. I'll probably put the ifs in the main loop. Might even be better... I know now at least what is possible and what is not.

About the second part...
That is exactly what I'm looking for, I think. I will try it quickly. (Holiday starts this afternoon, three weeks of holiday, so plenty of time.)

Thanks for responding so quickly, I am not responding quickly
Sort of little time due to study and the stupid reports that come with it

Login to post a reply

Server time is: 2024-09-27 22:28:15
Your offset time is: 2024-09-27 22:28:15