Page 15 of 17 FirstFirst ... 51314151617 LastLast
Results 141 to 150 of 167

Thread: The Programming Thread

  1. Top | #141
    Veteran Member
    Join Date
    Dec 2010
    Location
    Riverside City
    Posts
    4,601
    Archived
    6,289
    Total Posts
    10,890
    Rep Power
    44
    Quote Originally Posted by lpetrich View Post
    Quote Originally Posted by fromderinside View Post

    Bad bet. APL is much more efficient. My little brother, almost 78, up in Ilwaco WN has been replacing COBOL with APL for banks, Insurance companies, and Oil Companies for over 40 years.
    APL? There's a programming language with that name, but it uses lots of extra symbols, and it is very terse. Why APL and not (say) Python?
    Because Python was not around when New Jersey digitized their unemployment claim processing in the 1970s. They had a choice between COBOL, Lisp, ForTran, and APL, and a few more that are even more obscure today - and two of these explicitly targeted a scientific rather than administrative applications.

  2. Top | #142
    Elder Contributor barbos's Avatar
    Join Date
    Nov 2005
    Location
    Mlky Way galaxy
    Posts
    11,986
    Archived
    8,047
    Total Posts
    20,033
    Rep Power
    70
    Quote Originally Posted by Jokodo View Post
    Quote Originally Posted by barbos View Post
    Quote Originally Posted by Jokodo View Post
    Any COBOL programmers looking for a new job? https://qz.com/1832988/covid-19-resu...-cobol-coders/
    Desperate enough to have russians from Russia?
    $80 per hour, I can learn COBOL in two days for that.
    At this point, they might well take active ISIS fighters as long as they agree to work 100% remotely. So go for it!
    I thought russians were worse than ISIS.

  3. Top | #143
    Contributor
    Join Date
    Nov 2017
    Location
    seattle
    Posts
    7,125
    Rep Power
    22
    I’m not doing anything serious, but needed to plot for loking at math and sciene. I didn’t want to go to the trouble of installing a graphics package so I took the path of least resistance and imported to Scilab. Scilab is ok for coding but it is a slow intrpreter and the debugger is not very good.
    Visual Studio is pretty good.

    Sciab has a full range of 2d.3d plots abd exort functions. Easy install.

    #include "steve.h"
    #include <fstream>
    #include <iomanip>
    using namespace std;

    int main()
    {
    ofstream testfile;
    testfile.open("example.txt");
    float x,y, dt,t;
    dt = 0.01;
    for (t = 0; t <= 1 ; t += dt) {
    x = sin(_PI2 * t);
    y = cos(_PI2 * t);
    cout << t << setw(20) << x << setw(20) << y << "\n";
    testfile << t << setw(20) << x << setw(20) << y << "\n";
    }
    testfile.close();
    return 0;
    }
    //sclab
    clear
    [f1,err] = mopen("c:\\documents\SCILAB\example.txt","rt")
    if(err < 0)then disp("file open error");end;
    // -1 go to end of file
    x=mfscanf(-1,f1,' %e %e %e')
    // r rows c columns
    [r,c] = size(x)
    err = mclose("all")
    if(err < 0) then disp("file close error")end;
    plot2d(x(1:r,1),x(1:r,2))
    g=gca()
    g.x_location = "middle"
    xs2png(w1,"c:\documents\scilab\plots\fig1")


  4. Top | #144
    Contributor
    Join Date
    Nov 2017
    Location
    seattle
    Posts
    7,125
    Rep Power
    22
    A make work project to keep busy, a low pass digital filter. It us under the category of real time systems.

    In a real implementation an analog to digital converter would be sampling a signal and pushing samples into a buffer the length of the number of filter coefficients. The filter has to execute and an output generated before the next input sample.

    The filter is auto-regressive. At any sample n the filter operates on the sample plus the previous number of samples equal to the filter length.

    There are different algorithms to generate filter coefficients. That would be a math thread.

    The simulation is mot entirely accurate, it uses floating point. In a real system the output and input to analog digital converters are signed integers that limit the accuracy and resolution.



    #include "steve.h""
    #include <fstream>
    #include <iomanip>
    using namespace std;

    void make_sin(float fs, double x[], double y[],int sf, double tmax, int msize) {
    int i;
    double dt,t;
    dt = 1/fs;
    t = 0;
    for (i = 0; i < msize; i++) {
    x[i] = t;
    y[i] = sin(_PI2 * sf * t);
    t += dt;
    }
    }

    void fir_lp(double isig[], double osig[], double coef[], int lencoef, int lensig) {
    // low pass filter
    int i, j, k, n;
    double acc;
    double* buffer = new double[lencoef];
    // initialize the input buffer
    for (i = 0; i < lencoef; i++)buffer[i] = 0;
    k = 0;
    for (i = 0; i < lensig; i++) {
    acc = 0;
    for (j = 0; j < lencoef; j++) acc += coef[j] * buffer[j]);
    osig[k++] = acc; // output to digital to analog converter
    //push new analog to digital converter sample onto the buffer.
    for (n = 1; n < lencoef; n++)buffer[n - 1] = buffer[n];
    buffer[lencoef - 1] = isig[i];
    }
    delete [] buffer;
    }

    int main()
    {
    double samp_freq,tmax;
    int sig_freq, i, n, ncoef, msize;
    // get filter coefficients
    ifstream coeffile;
    coeffile.open("coef.txt");
    coeffile >> ncoef; // filter length
    coeffile >> tmax; // simulation time
    double* coef = new double[ncoef];
    for (i = 0; i < ncoef; i++) coeffile >> coef[i];
    coeffile.close();
    sig_freq = 1; //hertz sampling frequency
    samp_freq = 100; //hertz sample frequency
    msize = ceil(tmax * samp_freq); //array size
    double* x = new double[msize];
    double* filtin = new double[msize];
    double* filtout = new double[msize];
    ofstream outfile;
    outfile.open("lpout.txt");
    make_sin(samp_freq, x, filtin, sig_freq,tmax,msize);
    fir_lp(filtin, filtout, coef,ncoef,msize);
    for(i=0;i < msize; i++)outfile << x[i] << " " << filtin[i] << " "<< filtout[i] << "\n";
    outfile.close();
    delete [] x;
    delete [] filtin;
    delete [] filtout;
    return(0);
    }

  5. Top | #145
    Veteran Member excreationist's Avatar
    Join Date
    Aug 2000
    Location
    Australia
    Posts
    1,378
    Archived
    4,886
    Total Posts
    6,264
    Rep Power
    78
    Quote Originally Posted by steve_bank View Post
    ....
    Code:
    #include "steve.h""
    #include <fstream>
    #include <iomanip>
    using namespace std;
    
    void make_sin(float fs, double x[], double y[],int sf, double tmax, int msize) {
        int i;
        double dt,t;
        dt = 1/fs;
        t = 0;
        for (i = 0; i < msize; i++) {
            x[i] = t;
            y[i] = sin(_PI2 * sf * t);
            t += dt;
        }
    }
    Hi I was just testing out the code tag on your code.... it even automatically fixed all of the indentation.... which is nice....

    Code:
    int main()
    {
    double samp_freq,tmax;
    int sig_freq, i, n, ncoef, msize;
    // get filter coefficients
    ifstream coeffile;
    coeffile.open("coef.txt");
    coeffile >> ncoef; // filter length
    coeffile >> tmax; // simulation time
    double* coef = new double[ncoef];
    for (i = 0; i < ncoef; i++) coeffile >> coef[i];
    coeffile.close();
    sig_freq = 1; //hertz sampling frequency
    samp_freq = 100; //hertz sample frequency
    msize = ceil(tmax * samp_freq); //array size
    double* x = new double[msize];
    double* filtin = new double[msize];
    double* filtout = new double[msize];
    ofstream outfile;
    outfile.open("lpout.txt");
    make_sin(samp_freq, x, filtin, sig_freq,tmax,msize);
    fir_lp(filtin, filtout, coef,ncoef,msize);
    for(i=0;i < msize; i++)outfile << x[i] << " " << filtin[i] << " "<< filtout[i] << "\n";
    outfile.close();
    delete [] x;
    delete [] filtin;
    delete [] filtout;
    return(0);
    }
    Edit: it didn't fix the indentation for that - oh well....

  6. Top | #146
    Contributor
    Join Date
    Nov 2017
    Location
    seattle
    Posts
    7,125
    Rep Power
    22
    The frequency response of the filter and the output for a sin input. The startup delay is the buffer filling up.





  7. Top | #147
    Contributor
    Join Date
    Nov 2017
    Location
    seattle
    Posts
    7,125
    Rep Power
    22
    The coef .txt file

    33
    2
    -0.0086827058
    0.0144278375
    0.0113203161
    -0.0080360033
    -0.0091899954
    -0.0009891973
    0.0227447187
    0.0087521368
    -0.0368257634
    -0.0127543525
    0.0378075284
    0.0365069835
    -0.0368261824
    -0.0971619203
    0.0483744099
    0.3187605599
    0.4425552553
    0.3187605599
    0.0483744099
    -0.0971619203
    -0.0368261824
    0.0365069835
    0.0378075284
    -0.0127543525
    -0.0368257634
    0.0087521368
    0.0227447187
    -0.0009891973
    -0.0091899954
    -0.0080360033
    0.0113203161
    0.0144278375
    -0.0086827058

  8. Top | #148
    Contributor
    Join Date
    Nov 2017
    Location
    seattle
    Posts
    7,125
    Rep Power
    22
    Found this on the net while looking for something else. Truncation/rounding at a decimal place. Shift left, round to get rid of unwanted digits, shift back.


    double dec_places(double val, unsigned long long int n) {
    unsigned long long int dp = pow(10, n);
    return(round(val * dp) / dp);
    }

    int main() {
    double xf, x = 1.123456789;
    unsigned long long int n_dec = 5;
    xf = dec_places(x, n_dec);
    printf(" x %2.15f xf %2.15f \n", x, xf);
    }

  9. Top | #149
    Administrator lpetrich's Avatar
    Join Date
    Jul 2000
    Location
    Eugene, OR
    Posts
    15,634
    Archived
    16,829
    Total Posts
    32,463
    Rep Power
    95
    That leads to think. What might be the best sorts of languages for exploratory / experimental sorts of programming?

    I like computer-algebra software.

    List of computer algebra systems

  10. Top | #150
    Administrator lpetrich's Avatar
    Join Date
    Jul 2000
    Location
    Eugene, OR
    Posts
    15,634
    Archived
    16,829
    Total Posts
    32,463
    Rep Power
    95
    If you want to do number crunching with big blocks of data, here is what might be useful:


    For general-purpose programming, I propose this spectrum:
    • Python - dynamic typing, easy to start with
    • Java - static typing, generics, garbage collection
    • C++ - static typing, generics, semi-explicit memory management - designed for high performance

    For experimental or exploratory programming, I do NOT recommend plain C. One has to do a LOT of stuff by hand by it, and its preprocessor and its memory management are just plain bug-prone.

    C++ supports several safe alternatives.

    One can declare constants with "const", as a type-safe alternative to preprocessor declarations.

    One can also use "const" for function args and method declarations, as a way of stating that something will not be changed.

    Templates are a good type-safe alternative to preprocessor functions.

    Its Standard Template Library is a set of collection classes and functions for working with them, and a nice thing about them is that one does not have to worry about memory leaks. The collections deallocate all their allocated memory when they go out of scope.

    C++ now supports anonymous functions (lambdas), and that should make some uses of it a LOT easier.

Similar Threads

  1. Python programming project
    By excreationist in forum Computers and Technology
    Replies: 11
    Last Post: 05-11-2019, 05:37 AM
  2. Some new programming languages
    By lpetrich in forum Computers and Technology
    Replies: 6
    Last Post: 04-17-2019, 02:36 AM
  3. Web Programming - Web Assembly?
    By lpetrich in forum Computers and Technology
    Replies: 4
    Last Post: 04-16-2019, 11:16 PM
  4. Metaphysical programming
    By DracoAstreus in forum Metaphysics
    Replies: 4
    Last Post: 08-02-2016, 03:24 PM

Posting Permissions

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