Skip to main content
1-Visitor
April 29, 2015
Solved

Program to find area with Trap rule, but input parameter is tabular data, while output is value of integral

  • April 29, 2015
  • 21 replies
  • 6547 views

Hi guys, I am finishing up a course focused on half Excel and half Mathcad, with a smaller focus on the programing part of mathcad. I am having a lot of difficulties creating certain programs. My professor is finishing up the course with a small assignment that i cant seem to figure out. I AM NOT trying to get someone to do my work for me, I'm just truly lost when it comes to programming. Anyway, I attached an image of the description of the program she wants. I am familiar with the Trapezoidal rule (from my other math classes), and can come up with a simple program for Trap rule, but not with input parameters being tabular data. I'm not sure if this is a really simple program and I'm just not seeing it, but any help would be awesome! thanks!

Screen Shot 2015-04-29 at 11.21.33 AM.jpgScreen Shot 2015-04-29 at 11.21.21 AM.jpg

Best answer by RichardJ

Use local assignments with column operators on the first two lines of the program to split the table into two vectors:

21 replies

23-Emerald V
April 29, 2015

The clue is in the text of the question. Although an integral is often the easy way to calculate the area given a function, you will have to sum all of the individual areas (defined by neighbouring x and y points. (You could convert the data to a function by one of fitting functions, but that doesn't appear to be what she's after so go for the "obvious" route).

A simple approach would be to create an x and y vector using your data,

then write a program that

....uses a for loop to caculate each area and assign it to a vector A (Mathcad's indices make the A<sub>i</sub> calculations look almost identical to the printed version you've shown),

....and then use the vector sum operator to add up all of the elements of A and returns the sum.

There are other ways of doing it, but this one is fairly straigtforward and meets the implicit need to "write a program".

Stuart

aalvarez1-VisitorAuthor
1-Visitor
April 29, 2015

that seems like a straight forward approach with the Trap rule. my only issue is she wants the input parameters as "a tabular data", not in vector form. Unless theres someway of tricking mathcad into thinking the tabular data is actually two vectors. I'm going to ask her if vector inputs would be meeting her criteria. Thanks for your help/input. I really appreciate it!

RichardJ19-TanzaniteAnswer
19-Tanzanite
April 29, 2015

Use local assignments with column operators on the first two lines of the program to split the table into two vectors: