Author Topic: Mathematical Problems  (Read 2861 times)

0 Members and 1 Guest are viewing this topic.

Offline lomalena

  • Newbie
  • Posts: 6
    • View Profile
Mathematical Problems
« on: February 29, 2020, 08:05:09 am »
Hello, I'm new in qb64 and we are using this in our master's degree classes. Since I'm an architect and programming is very hard for me to understand.

I have a question that I cannot figure it out.

For example, I have a function lets say f(x)=sin(x)+5
I want to divide that function into random 4 pieces and I want to find the coordinates of the points which cut the function.

I started like this but I don't know how to solve it.

Can someone plz help? Thank you.

OPTION _EXPLICIT
DIM m AS INTEGER
INPUT "how many pieces should we divide", m
DIM n AS INTEGER

FUNCTION fx (x AS DOUBLE)
    fx = SIN(x) + 5
FOR

NEXT

END FUNCTION
well I have no idea that what I am doing.

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Mathematical Problems
« Reply #1 on: February 29, 2020, 08:27:06 am »
Are you asking for the coordinates of the blue diamonds given random x1 x2 x3 etc? See below.
You're not done when it works, you're done when it's right.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Mathematical Problems
« Reply #2 on: February 29, 2020, 12:30:40 pm »
Code: QB64: [Select]
  1. _TITLE "Quick SIN Plot" 'b+ 2020-02-29
  2. SCREEN _NEWIMAGE(1000, 600, 32) ' 800 x 600 window allowing graphics ie 32 bit color or RGB and RGBA
  3. amplitude = 200
  4. yCenter = _HEIGHT / 2
  5.  
  6. 'lets plot sin(x)
  7. FOR x = 0 TO _WIDTH - 350
  8.     y = yCenter + amplitude * SIN(_D2R(x)) '_D2R is a degrees to Radians function
  9.     PSET (x, y), &HFFFF0000
  10. INPUT "How many points along x axis "; xPts
  11. FOR i = 1 TO xPts
  12.     x = RND * (_WIDTH - 350) ' rand x on screen's x axis
  13.     y = yCenter + amplitude * SIN(_D2R(x))
  14.     PSET (x, y), &HFFFFFF00
  15.     CIRCLE (x, y), 2, &HFF0000FF
  16.     _PRINTSTRING (x - 12, y - 20), STR$(i)
  17.      LOCATE i, (_WIDTH - 350) \ 8 + 2: PRINT "Point"; i; " x ="; INT(x); ", y ="; INT(y) '<<< fix location
  18.  

EDIT: fix location
« Last Edit: February 29, 2020, 12:50:37 pm by bplus »

Offline lomalena

  • Newbie
  • Posts: 6
    • View Profile
Re: Mathematical Problems
« Reply #3 on: February 29, 2020, 05:58:15 pm »
Thank you so much :D

I think I understand now. I will try to make it more simple maybe :D Thank you so much!