The above video goes away if you are a member and logged in, so log in now!

 Would you like to get all the newest Gaming News fromQJ.NET in your email each day? Want to learn more about the team who brings you the QJ news?

## C/C++ Coding for my Math homework lol

This is a discussion on C/C++ Coding for my Math homework lol within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; lol this is awesome, i just coded all my math problems into a c/c++ source coide and complied it and ...

 Tweet
1. ## C/C++ Coding for my Math homework lol

lol this is awesome, i just coded all my math problems into a c/c++ source coide and complied it and it workd lol, now i dont have to worry about bying or using a computer calculator for it anymore, heres an example of what you would do. feel free to use it but its a function that i called and such so i wouldnt use it if i were u.
P.S>. i just worte this from scratch so if there are any errors than thats me not paying attention fault.

Code:
```
int Problem1()
int x;
int y = 40;
y - 20 / 4 = x \\ 4x + 20 = y
return x;
printf("Problem 1: %i", x);
}```
o and i mae y and integer because i just wanted to see if multiple integers worked and it did

all u have to know is the process, thats all, no actual calcualating lol

2. seems like a job for python....

3. lol i dunno but it sure makes my homewokr easier, seeing as how i dont need a calculator and i have hte math.c right there for all ym problems

4. Make it take input, basically make a calculator. :)

5. i know but then addding a variable input also is just hard, so i mjust gonnam make them in hte code its selfand print out hte answer

6. i would eat your shoes if you would create a solver prog. im try it but i doubt anything will happen

1534x(squared) + 190x+300

try doing that with the quadtratic formula ><

7. hehe using your PSP for homework, thats a new one, I like the idea tho, so I am going to intergrate my atari assembly language into MasterXConsole (MasterX Windows) and let you pass the instructions to the program one by one.. I need to fix the mouse and allow the user to use the D-Pad on the keyboard.. but hey youll be able to do your math homework without using a compiler...

- Lostjared

8. Yeah I wouldn't mind making a program that plots lines and curves, that would be sweet...input some variable and away it goes...

9. tha shudnt be too difficult u cud make a method recursive method
for example say u want to plot y = x
first wud have to make the window, by default make it like 100 by100 or something
then a recursive method
void plot(int x){
y = x
at coordinates x, y make a lil dot
x+= .01 //or some small number
}

well of course u wud have to make an origin which cud be equal to windowWidth/2,windowheight/2 and i guess the rest of the doin just falls into place

10. ya i guess thats true, but chingwyn, anyidea on how to make gravity yet? ive been working but no luck :Cry:

11. ## Graph Eboot

Here's some code I just created for graphing algorithms. It's very bare at the moment, but I think I could throw quite a few flourishes in there (user selectable algorithms, zooming in, graph lines etc).
That, and it's more a proof of concept...

Code:
```#include <pspdisplay.h>
#include <pspctrl.h>
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspgu.h>
#include <png.h>
#include <stdio.h>
#include <psppower.h>
#include "graphics.h"
#include "callback.h"
#define RGB(r, g, b) ((b << 16) | (g << 8) | r)
#define printf pspDebugScreenPrintf

PSP_MODULE_INFO("Graph Example", 0, 1, 1);

int main() {
scePowerSetClockFrequency(333, 333, 166);
pspDebugScreenInit();
SetupCallbacks();
initGraphics();
int sx = 0, sy = 0, r = 225;

while(1)
{

int x = -240;
int y = -136;
while (y < 136){
while (x < 240){

if (x == 0) // axis
putPixelScreen(RGB(5, 5, 50), x+240, y+136);

if (y == 0) // axis
putPixelScreen(RGB(5, 5, 50), x+240, y+136);

if (x == y) // x = y
putPixelScreen(RGB(255, 255, 255), x+240, y+136);

if ( ((x*x)+(2*x)) == y) // ax^2 + bx + c
putPixelScreen(RGB(255, 255, 255), x+240, y+136);

if ( (x*x) + (y*y) == r )  // x^2 + y^2 = r^2
putPixelScreen(RGB(255, 255, 255), x+240, y+136);

x++;
}
x= -240;
y++;
}

flipScreen();
sceKernelDelayThread(25000); // allows Home exiting to work
} // while

return 0;
} // main```
It runs along the same concept as ray tracers do, except only using two axis. That means on the more complex algorithms (the circle and parabola for instance) that it ends up missing some points.
You could do a very similar function involving the use of lines instead of point tests however.

That could be fixed a few ways however, and for all intents and purposes it works well enough.

Also, you can fill in the circle by changing if ( (x*x) + (y*y) == r ) to if ( (x*x) + (y*y) < r )

For the lazy sods who just want the eboot lol, they're in rar at http://www.smerity.com/curve.rar and for those who want full source code, http://www.smerity.com/curvesource.rar

12. SG57---
LMMFAO my fault i completely forgot about it ill c wat i can do right

13. wow, i now like how to make tic tac toe with java (barely)

14. I've been researching working with physics in the last week or so, in the hopes of making Traveller smoother, aswell as the prospect of creating a multi-player scorched earth game. So many ideas, I just wish I had the time to see them all through.

Once I'm done cutting down server/client code for another project, I'll be sure to write up a quick scorched-earth style engine. One of these days one of my projects will be complete ;)

15. realn0whereman, you n00b :P, it would'nt be that hard to do that just make it take the quadratic formula variables, a b and c, then run them through, (-b+-sqroot(b(squared)-4(a)(c)))/(2(a)) Finding what functions to use in math.h would be the hard part.

16. Here's a complete list of functions in math.h, including descriptions and examples. Have fun

17. ravine, itd probably take me a day or so to find those functions ad i dont ahve the time so i aint doing it, knock ur self out others guyz lol anyawy, chingwyn, ive been trying to get gravity but i cant get the sleep(2500); to work, or even if thats one, or the scekernelDelayThread(); either, i just need someway to pause soemthing for like say, 1/4 sseconds, ve tryed the sceDisplayWaitVblankStart (); inside the for(i = 0; i<x; i++) { but my psp freezes because its so dman big of an aruguemnt for some reason, o well, hoep i get an answer so i can implament it into my credits, and into my main game, thats why i ahvnt posted on here for while about kitty cannon been trying for days to get a gravity engine (if you will) gooing, but its hard, the only way im seeing now is do alot of greater than and less than calls like this:

Code:
```
if(catx >= 100) {
catx++; // so when i shoot the cannon the cat keeps flying
for(catx >= 200) { //so the cat starts to descent
caty--;
}```
i dunno, 9m getting a head ache just trying to figure it out nad on my laptop iu just got, i got cygwin etc. setup, so now i cna code in my room and such, but the complier is a biut slow so its installing SDL right now and im waiting

i have one question that could answer all my problems, how do i increment an integer by one at a set speed? emaing, the catx speed ++ at the speed of every 1/8 second, so i can shoot it out wihtout having to holding down the fire button like in hte demo? please some help with some basic questions

18. Originally Posted by Psilocybeing
Here's a complete list of functions in math.h, including descriptions and examples. Have fun
hey thanks, maybe i cna integrate a time into my game meaning gravity! just need help figuring out how tho, i just need a counter basically thatll count up and if the counter + 20, then catx +

WAIT didnt the tutorial have a counter!?>!?!?!?!?!?, holy ****, im gonna go and see what i can do, but chingwyn, pleaes post what u ahve for ur gravity or ur ideas or something,

19. I wrote a program a while back for PSP that solves quadratic equations using the quadratic formula. I guess I'll release it with source tomorrow, I haven't got time today.

20. k thats cool, ill take a look at that to learn aboutb the math.c functions and calls more, u alwasy cant learn not enough

21. Originally Posted by Ravine
realn0whereman, you n00b :P, it would'nt be that hard to do that just make it take the quadratic formula variables, a b and c, then run them through, (-b+-sqroot(b(squared)-4(a)(c)))/(2(a)) Finding what functions to use in math.h would be the hard part.
ravine u panzy!. i know where u sit from 12 -12:30!! lol

i have mrs. mulligan for honors algebra 2 and shes pretty fckin hard / but fun

i just wanna whip out my psp during a test and be like pssshhh my stolen ti-84 is so ghetto

22. Originally Posted by Ravine
realn0whereman, you n00b :P, it would'nt be that hard to do that just make it take the quadratic formula variables, a b and c, then run them through, (-b+-sqroot(b(squared)-4(a)(c)))/(2(a)) Finding what functions to use in math.h would be the hard part.
wait, do you mean llike the square root symbol/function? i found that already, forgot it tho, its in the libs directory somewhere, i also learned the pi call

23. Yeah, the square root function. That should do what you want. Also, find the square function, or make it urself (b*b)

24. Why dosnt any one make a port of the TI87 or TI89 Calculators.

The whole OS is C and it is saved on the devices flash, which is compleatly acessable.
would proubly take all of about a day

25. Originally Posted by Smerity
It runs along the same concept as ray tracers do, except only using two axis. That means on the more complex algorithms (the circle and parabola for instance) that it ends up missing some points.
You could do a very similar function involving the use of lines instead of point tests however.

That could be fixed a few ways however, and for all intents and purposes it works well enough.
The easiest way to fix that up is to change from thinking of the points on the screen as points, and think of them as squares.

i.e. if you stick to discrete values of x=0, 1, 2, 3 and y=0, 1, 2, 3, then you're leaving big gaps in the spaces between numbers - what about x=0.1, 0.2 etc.?

Try considering each pixel as covering a range from e.g. x = (n - 0.5) to x = (n + 0.5).

You have to do a little thinking about what that means for your formulae, but for example you could change:

Code:
`if (((x*x) + (2*x)) == y) then ...`
into

Code:
```value = (x*x) + (2*x);
if ((value > (y - 0.5)) &&
(value < (y + 0.5))  then ...```
and that should draw your curve more smoothly.

You might also find that in that case, if y is changing rapidly between values of x, then you end up with big vertical gaps. In that case, you could experiment with incrementing x by less than 1 each time - e.g. use a step size of 0.1. This would be slower, but smoother.

The big advantage of your ray-tracing approach (which is pretty neat, by the way) is that it handles formulae that can have multiple values of y for a given value of x (and vice versa). If you don't need to handle multiple values, then a very quick curve plotter that leaves no gaps can be done by iterating over values for 1 axis, and drawing lines between the corresponding value points on the other axis.

e.g. if x=1 => y=2 and x=2 => y=4, draw a line from (1,2) to (2,4).

It's all quite an interesting topic, and you'd probably learn more about general mathematical principles by exploring the graph drawing problem than you'd learn from the homework in the first place.

26. i would eat your shoes if you would create a solver prog. im try it but i doubt anything will happen

1534x(squared) + 190x+300

try doing that with the quadtratic formula ><
[QUOTE] OMG! thats what i learned yesterday ^_^

27. Well here it is, my first actual release. I don't know if I should create a new thread or if this will be on the front page, but whatever. This program calculates any quadratic equation using the quadratic formula. IT DOES NOT EXIT THROUGH HOME, it will just freeze. Use select to exit, I know this has something to do with the loops, but I don't feel like finding/fixing the problem ATM. The source is included, currently this is all written out with a bunch of if statements, but I've got mostly written a function that should be able to replace most of them, its included if someone else would like to try to implement it, it wouldn't really affect the program. From the readme:

controls:
triangle adds 1 to the value of the current variable
cross subtracts 1 from the value of the current variable
circle adds 5 to the value of the current variable
square subtracts 5 from the value of the current variable
RTrigger adds 20 to the value of the current variable
LTrigger subtracts 20 from the value of the current variable

Select Exits, do not use home!!! I need to fix this.

Up and down change which variable's value you are changing, and while on the C (constant) variable press START to calculate the roots.

-------
I just learned about parabolas today in math, and I think I'd be able to write a program that could graph those, just thought I'd let you know about that a program for that might be coming.
Hope this is helpful for any other high school freshmen!

28. SG57, that algebra equation in your first post, was extremely simple. I can't believe you don't do that in your head. I often times completely factor the roots of quadratic equations all in my head on homework. If you want to do mentally like that, just start doing everything mentally, and you'll start speeding up, and all the new stuff you learn in math class do mentally as well, eventually you can remember more numbers at once, its pretty cool.

29. Fanjita -

Thanks :icon_smil Yeah, there are quite a few problems and advantages with ray tracing as you say, but I just really love the concept lol
You hit the main advantage for graphing right on the head, the ability to plot algorithms with multiple values.

The other thing that I like about is that I can make some collision detection stuff pretty quickly for it, ie, if I wanted an object clickable by a cursor :

Code:
```        x = cursor.x
y = cursor.y
if ((x-sphX)*(x-sphX) + (y-sphY)*(y-sphY) < r){

printf("Hovering over button \n");

printf("Button pressed \n");

}```
Also, on your idea of subdividing the pixels into small samples, very good idea, I can't believe I missed it lol. The other advantage to that is that you could implement a form of antialiasing at the same time, ie, there are four samples for a pixel, you test all the samples and then the pixel's colour becomes :

Code:
```samples = 4; // samples per pixel
hit = 3; // number of samples that actually collided
float colour = 255.0/samples;
float pixelcolour = samples*hit;
putPixelScreen(RGB(pixelcolour, pixelcolour, pixelcolour), x, y);```
Bang! You just got four (five if you count black) different shades of white, giving it a nice little antialiasing effect =)

Anyway, thanks for exchanging ideas, it was fun! lol

PS. Good work on the 2.0+ boot loaders et al, it's very very important for me. I was lucky enough to buy a firmware 1.5 PSP in Hong Kong, but back here in Australia, my friends have bought PSPs and they come standard with firmware 2.01s, so tragic! lol

30. Originally Posted by soccerPMN
SG57, that algebra equation in your first post, was extremely simple. I can't believe you don't do that in your head. I often times completely factor the roots of quadratic equations all in my head on homework. If you want to do mentally like that, just start doing everything mentally, and you'll start speeding up, and all the new stuff you learn in math class do mentally as well, eventually you can remember more numbers at once, its pretty cool.

Page 1 of 2 1 2 Last

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

All times are GMT -8. The time now is 05:59 PM.

Use of this Web site constitutes acceptance of the TERMS & CONDITIONS and PRIVACY POLICY