Skip to first unread message
Assigned to scottfr...@gmail.com by me

dogged...@gmail.com

unread,
Jun 23, 2014, 10:49:15 PM6/23/14
to mitappinv...@googlegroups.com
I used The Trapezoidal Rule to integral  , but the The result looks wrong
the Fig at left is the code
i use the different in time to get the trapezoidal's upper base and lower base and the fixed pitch.
the Fig at right is the result.the green one is the original value. yellow one is the first order integral and the blue one is second order . 
it seems wrong.
Are there any other better way to integral in AI2?
thx~

Scott Ferguson

unread,
Jun 24, 2014, 7:12:29 AM6/24/14
to mitappinv...@googlegroups.com
Where did you find the algorithm to build your blocks?
That would help me to check your work.
I find that math algorithms in javascript are sometimes close enough to App Inventor's Math blocks to convert from one to the other.
Pseudocode algorithms are helpful also.
I don't know how to convert a series in Calculus form directly to App Inventor blocks, however.
---
Scott

dogged...@gmail.com

unread,
Jun 24, 2014, 7:35:51 AM6/24/14
to mitappinv...@googlegroups.com
 different in time to get the trapezoidal's upper base and lower base
fixed pitch is 0.02sec 

Scott Ferguson

unread,
Jun 24, 2014, 8:15:06 AM6/24/14
to mitappinv...@googlegroups.com
I don't know how to convert that notation to App Inventor blocks. 
You would need an algorithm to show me that represents some other computer programming language or pseudocode that can be translated into App Inventor blocks. The ones that I have seen so far today are not helpful. Javascript is probably one of the best if you can find an example.
---
Scott

Abraham Getzler

unread,
Jun 24, 2014, 11:02:13 AM6/24/14
to mitappinv...@googlegroups.com
Your yellow integral curve looks reasonable to me, based on your green data curve.
The yellow line rises in the areas where the green curve is mostly above zero,
and it stays flat in areas where the green curve oscillates about zero.

ABG

dogged...@gmail.com

unread,
Jun 25, 2014, 12:17:31 AM6/25/14
to mitappinv...@googlegroups.com
this Fig is the 921 earthquake 's seismic waves . It's accel and velocity
and displacement.
Compare with my result . my velocity is not wave clearly and similar with
displacment.














and this the integral of C  use the smae method Trapezoidal Rule
#include <stdio.h>

#include <math.h>

double my_eq_orig(double x)
{
    return 0.2 + 25*x - 200*pow(x, 2) + 675*pow(x, 3) - 900*pow(x, 4)
+ 400*pow(x, 5);
}

double my_eq(double x)
{
    return -400 + 4050*x - 10800*pow(x, 2) + 8000*pow(x,3);
}

double integrate_trapezoidal(double (*fx)(double), int n, double a, double b)
{
    int i;
    double h;
    double x = a;
    double s = 0;

    h = (b - a) / n;
    for (i=1;i<=n-1;i++) {
        x += h;
        s = s + fx(x);
    }

    return h * ((fx(a) + fx(b)) / 2 + s);
}

void main(void)
{
    /* real */
    double real = integrate_trapezoidal(my_eq_orig, 100, 0, 0.8);
    /* n = 1 */
    double real_i = integrate_trapezoidal(my_eq_orig, 1, 0, 0.8);
    /* average */
    double fa = integrate_trapezoidal(my_eq, 100, 0, 0.8) / 0.8;

    printf("real value:\n%lf\n\n", real);
    printf("I:\n%lf\n\n", real_i);
    printf("f(x)\'\' average:\n%lf\n\n", fa);
    printf("Error:\n%lf\n", -(fa * pow(0.8, 3))/12);
}

SteveJG

unread,
Jun 25, 2014, 8:21:07 AM6/25/14
to
In your AI Android Seismograph, you are using live data from the AI2 Accelerometer?     What you see displayed 
on your graph is the result of :

1) an inexpensive hardware accellerometer.  whose mesurements are probably not precise
2) There is a significant time lag in the posting of AI2 graphics.  AI2's graphic capabilities are limited.  You might get better results by saving the data to a csv file, then later generating a graphic with a slow refresh rate using the csv or using the graphic capabilities of a Fusion Table or one of the other graphic tools that AI2 can access.   Your curves might be smoother as you only collect sets of numbers but do not attempt to graph in real time.
3) There is a time lag in the period the Android cpu is attempting to calculate the integral. The calculation  takes a few ms for each calculation.  Depending on your sampling interval, the time lag might be a serious issue.

Combine all those limitations, and the graph you display on the device screen is remarkable.

To get improvements, you might want to post your graphic blocks, if you are comfortable sharing that information.
You posted the java code, but you did not post the blocks you used to calculate.  You might have an error in  transcription and translation of the java code into blocks.

Regards,
Steve

Scott Ferguson

unread,
Jun 25, 2014, 8:49:15 AM6/25/14
to
You can try these blocks based on the C code you provided.
I don't know if the output is correct but it should function the same as the C code.
You can either merge the screen from the attached project into your app or just build your blocks based on my blocks if you choose to use them.


---
Scott
IntegralLibrary.aia

Abraham Getzler

unread,
Jun 25, 2014, 5:41:01 PM6/25/14
to mitappinv...@googlegroups.com
How does the width of your trapezoids compare to the usual peak to peak distance
of the original data on the x axis?

Your integral curve as originally posted looked so smooth that I'm guessing
your trapezoids are too few and too wide.

ABG


dogged...@gmail.com

unread,
Jun 25, 2014, 11:11:42 PM6/25/14
to mitappinv...@googlegroups.com
Thank you all .
I know this may Inaccurate compare with Real data because of it's acceleration sensor in phone.
But i have a series of tests to calculate the error.
The main of this app is provide the data to reference in the first time.
Attach my block.
Accelerometer_copy_copy.aia

dogged...@gmail.com

unread,
Jun 28, 2014, 5:41:36 AM6/28/14
to mitappinv...@googlegroups.com
To Steve JG :
     I have upload my block.aia.
To  Scott Ferguson :
     because the example have constant function and it integral from 1 to 1000 . I am new in write program, so i dont know how to rewrite to my blocks correctly.
     i have upload my block. U can see
To Abraham Getzler:
    my width equal 0.02 (sec)  I understand what you said . but I had zoom by 10,  my velocity still similar with displacment.

The aia at the previous

SteveJG

unread,
Jun 28, 2014, 12:05:57 PM6/28/14
to mitappinv...@googlegroups.com
I ran your code.   I think I a get smoother lines than you did on your phone.  The yellow and blue lines track closer together.   I am using a Samsung Tab II 7".

I modified your blocks to include a pause by turning on/off PlottingIntervalClock.Enabled    true/false.    It allows you to freeze the screen.

I experimented with   hiding the display of the PreVLabel, PreSLabel  in the hope not displaying the values would improve the graphing by making the display of the values visible or invisible.  Hiding did not seem to change things.
I am now making a version without the set PreVLabel etc   blocks.    I am hope I am eliminating any lag that might be caused by the Android taking the time to display the actual values of the points it is posting to the screen canvas.   I expect this will make a difference.

I want to post a Screen capture but I am having problems doing the Screen capture with my tablet..  I would like you to see what my screen looks like..I may have to take a photo.

more later

--Steve

dogged...@gmail.com

unread,
Jun 29, 2014, 12:15:26 AM6/29/14
to mitappinv...@googlegroups.com
TO SteveJG :
     I used  Samsung Note 3 , At the same time I have HTC one for comparison.
     It also the focus i want to investigate that the accel sensor in different mobile device's effect.
      My english isn't well . Please forgive me. 

SteveJG

unread,
Jun 29, 2014, 1:29:38 PM6/29/14
to mitappinv...@googlegroups.com
Your English is good enough.    謝謝       If I need to, I can get my son to translate what I say into Mandarin.  He spent almost two years studying in Beijing.

I expect the hardware performance of different phones and tablets might vary a lot depending on the quality of Android device and the device's cpu and version of Android.

I am still experimenting.

Regards,
Steve

dogged...@gmail.com

unread,
Jun 30, 2014, 4:12:23 AM6/30/14
to mitappinv...@googlegroups.com
No problem!
Thank your help.
Looking forward to hearing from you soon.
And I will tyr my best to slove the problem.
Reply all
Reply to author
Forward
0 new messages