From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use Mathscript Node to calculate integrals

Solved!
Go to solution

How do you use the command quadn_trap within a Mathscript Node to calculate the integral 5x^4 dx numerically. The upper bound is 1 and the lower bound is 0. The answer should be 1.

0 Kudos
Message 1 of 3
(4,002 Views)
Solution
Accepted by topic author bumptee5

Hello bumptee5,

To have the function evaluate 5x^4 the input vector should be x=[0,0,0,0,5]. The coefficients will follow [c,x,x^2…]. The way the quadn_trap function works the approximation will not be 1 but 2.5. If you want to evaluate the integral over the range use the quada_nc8 function.

f='5*x^4';

A=quada_nc8(f,0,1);

Wear
National Instruments
Product Support Engineer
Message 2 of 3
(3,955 Views)

Hey Wear,

 

Cool. Never even heard of quada_nc8 function. Works like a charm, just don't forget the semicolons or single quotation marks.

 

Thought you might be interested in where my question originated. I am studying the 'Hands-On Introduction to LabVIEW' by John Essick. Problem 5 in Chapter 3 reads:

 

It is easy to show analytically that the integral (he has the elongated S symbol for the bounds with upper=1 and lower=0) 5x^4dx equals exactly 1. Open a Mathscript Interactive Window and then type help quadn_trap in the Command Window, After learning the syntax of the Mathscript command help quadn_trap write a VI called  Numerical Integral that uses quadn_trap within a Mathscript Node to calculate the integral (again elongated S symbol with same bounds) 5x^4dx numerically and then displays the result in a front-panel indicator with Digits of Precision equal  to 5. For your numerical result to be correct to five decimal places (i.e., the first five decimal places are all zero), how many x- values must be supplied to quadn_trap within the integration range x=0 to x=1?

 

Thanks for your help!

btfever

0 Kudos
Message 3 of 3
(3,946 Views)