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.

Dark GDK / Function graphing

Author
Message
SunDawg
19
Years of Service
User Offline
Joined: 21st Dec 2004
Location: Massachusetts
Posted: 8th Apr 2008 01:29 Edited at: 8th Apr 2008 02:07
I'm working on a function-graphing program. The problem I've encountered is defining the function. I'd like to have the user input the equation, but I don't know what sort of data type could hold this information in a usable way. Below is an example of how it works, using a simple quadratic function. You'll notice I defined the function as (x*x). This is because (x^2) refused to function properly.

EDIT: Solved x^2 issue with pow(base,exponent) from math.h



My site, for various stuff that I make.
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 8th Apr 2008 02:51
I think you're talking about something that I've cogitated on for a long time but never did get around to implementing. However, I have spent some time thinking about it. I would think that the formula would have to be stored in a string. You'd then have to tokenize the string, maybe reducing specific math operations to tokens of their owns. As you scan the string from left to right you look for numeric values or variables. Once you've accumulated a value you push it on the stack. When you reach an operator you push it on the stack. If you run into a left parenz you need to push what you have on the stack, build whatever's in the the parenz and when you hit the right parenz you unstack everything, applying operations as you go, until you're pack at the left parenz. Whatever you accumulate inside parenz you push on the stack as a single value and continue past the right parenz. When you reach the end of the string, you pop the contents of the stack, accumulating it as you go and applying the operators.

It might be necessary to maintain separate stacks for values and operators.

Sorry I can't be more specific, but I'll probably never have time to tackle this problem at the level I'd like. It's more like working out a puzzle than being productive until I find a real need for it.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 8th Apr 2008 03:00
I think this is usally done by tokenizing first - for syntatic correctness and processing if its ok.

Then I think you use a recursive technique to get to the inner most equations, and then the recursive function returns the actual value.

Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 8th Apr 2008 03:36
I've always wanted to use this kind of technique to develop a language for creating sounds. Ummm. Maybe after the game is finished, which means post mortum.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 8th Apr 2008 03:38
Sounds? Like This? (baffled) Like a phenome thing? Speech? Music? Or like relaxation noises etc?

SunDawg
19
Years of Service
User Offline
Joined: 21st Dec 2004
Location: Massachusetts
Posted: 8th Apr 2008 03:43
Exactly what I feared I'd have to do. It's a neat tool, to be able to graph things on a PC where I can set absolutely every parameter and scale, but this is would be a massive undertaking for novelty. I'll see what I can do, and if I come up with some ingenious solution, I'll be sure to say so!

My site, for various stuff that I make.
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 8th Apr 2008 03:48
try http://www.fusioncharts.com - this might be of interest to you..maybe not...but maybe.

SunDawg
19
Years of Service
User Offline
Joined: 21st Dec 2004
Location: Massachusetts
Posted: 8th Apr 2008 03:52
Thanks, but I've already got the lovely TI-83+ for all my graphing needs. This project is just for fun and learning.

My site, for various stuff that I make.
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 8th Apr 2008 03:54
Just sounds in general. The way I perceive it would be tokens controlling values like volume, speed, frequency and others that direct the change in values like sweeps in those areas. Nested variances and multiple voices. Different wave forms.

I guess it would be more along the lines of sound effects. Someone over at Code Project has a project for a sound synthesizer as the basis for a synth machine. I'd probably find a lot of pointers over there.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 8th Apr 2008 03:58
I think you'd do better taping into your memory banks about how the SID chip worked and emulate that - You can control sound cards similarly by stuffing freq directly into em these days - even multivoiced of course. In short - you'd have a blast no matter how you did it!

Abzero
16
Years of Service
User Offline
Joined: 22nd Mar 2008
Location:
Posted: 13th Apr 2008 12:06
Quote: "I think you're talking about something that I've cogitated on for a long time but never did get around to implementing. However, I have spent some time thinking about it. I would think that the formula would have to be stored in a string. You'd then have to tokenize the string, maybe reducing specific math operations to tokens of their owns. As you scan the string from left to right you look for numeric values or variables. Once you've accumulated a value you push it on the stack. When you reach an operator you push it on the stack. If you run into a left parenz you need to push what you have on the stack, build whatever's in the the parenz and when you hit the right parenz you unstack everything, applying operations as you go, until you're pack at the left parenz. Whatever you accumulate inside parenz you push on the stack as a single value and continue past the right parenz. When you reach the end of the string, you pop the contents of the stack, accumulating it as you go and applying the operators.

It might be necessary to maintain separate stacks for values and operators.

Sorry I can't be more specific, but I'll probably never have time to tackle this problem at the level I'd like. It's more like working out a puzzle than being productive until I find a real need for it."


I think what your looking for here is polish, or indeed reverse polish notation;

you string would look like: + 35 35, or +,35,35 (for polish, and 35,35,+ for reverse)

then use a stack or two to evalue; so for example:

Login to post a reply

Server time is: 2024-09-29 17:22:35
Your offset time is: 2024-09-29 17:22:35