BBC BASIC for Windows
« How to code polynomial Regression »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 11:50pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: How to code polynomial Regression  (Read 805 times)
CharlesB
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 46
xx Re: How to code polynomial Regression
« Reply #2 on: Apr 23rd, 2015, 12:27am »

Wow, has this given me something to work with. When I first saw "polyfit.bas" in your example files I had no idea of what this program did.

Most of it is rather (far) over my head, but I will re-enter my data on a csv file.

My biggest problem (above) was simply how to code the formula, i.e. . . . "e+003)* x^0"

I mean, in a very utilitarian way, I still would like to know how I would put this in to proper BASIC code

f(x) = -7.2319868443561427e+003 * x^0
+ 3.9441606604906628e+004 * x^1
+ -7.9951577783959365e+004 * x^2
+ 7.1052066233486243e+004 * x^3
+ -2.2965143356506876e+004 * x^4

I can see how, in POLYFIT.BBC you have something like it . . . but without the perplexing "e"

Code:
    print "y = " fnusing("##.###", vector(0)) fnusing("+##.###", vector(1)) " x" \
      \    fnusing("+##.###", vector(2)) " x^2" fnusing("+##.###", vector(3)) " x^3" \
      \    fnusing("+##.###", vector(4)) " x^4" fnusing("+##.###", vector(5)) " x^5" 




Thank you Richard, for all of your help and for just creating this tool.
User IP Logged

rtr2
Guest
xx Re: How to code polynomial Regression
« Reply #3 on: Apr 23rd, 2015, 08:25am »

on Apr 23rd, 2015, 12:27am, CharlesB wrote:
I still would like to know how I would put this in to proper BASIC code

It is already "proper BASIC code". The only specific thing to watch is that the use of lowercase 'e' means that a *lowercase command is necessary to make it work correctly:

Code:
      *lowercase

      x = 0.1234

      f = -7.2319868443561427e+003 * x^0 \
      \ +  3.9441606604906628e+004 * x^1 \
      \ + -7.9951577783959365e+004 * x^2 \
      \ +  7.1052066233486243e+004 * x^3 \
      \ + -2.2965143356506876e+004 * x^4

      PRINT f 

Richard.
User IP Logged

CharlesB
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 46
xx Re: How to code polynomial Regression
« Reply #4 on: Apr 24th, 2015, 4:13pm »

Thank you Richard.
This worked for me!


Also, I read the section on *LOWERCASE and the Star command summary ... learned a few very helpful things.


Further, I downloaded your polyfit.exe and it was a work of beauty. But when I downloaded polyfit.bas and looked into the code, it seems to me that the program looks for a polyfit.csv file in its own directory. I created such a file of about three hundred lines for x,y values. However, when I "Load & plot file" I see no dots, and when I "Fit polynomial," I get very strange results.

I'm not sure what I did wrong, but in any case, I thank you for your help.
User IP Logged

rtr2
Guest
xx Re: How to code polynomial Regression
« Reply #5 on: Apr 24th, 2015, 5:16pm »

on Apr 24th, 2015, 4:13pm, CharlesB wrote:
However, when I "Load & plot file" I see no dots... I'm not sure what I did wrong.

Did you modify the program to account for the hugely reduced number of data points? If you didn't, your data will be squashed into only about 1.5% of the width of the plot and inevitably the fitted polynomial is likely to 'blow up' outside that range.

The code at the website is just a demonstration, and is not designed to accept an arbitrary data file (e.g. it doesn't automatically scale the plot to the number and range of values in the file); it doesn't even allow you to choose the degree of polynomial!

The hope is that the code is structured in such a clear way that it is easy to modify to your own requirements.

Richard.
User IP Logged

CharlesB
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 46
xx Re: How to code polynomial Regression
« Reply #6 on: Apr 24th, 2015, 9:15pm »

Thank you Richard; I knew that it was a demonstration program and I did notice that it was only designed for a five degree polynomial . . . but I'm such a novice that I did not recognize the need to modify the program for the small data file.

It gives me something to learn. You are absolutely right, my regression line was "blown up" outside the range.


User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls