cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

How to calculate each colored area for this graph made by points?

Cornel
19-Tanzanite

How to calculate each colored area for this graph made by points?

Hello,

I have these points:

Cornel_1-1715330011989.png


How to calculate each colored area from below plot made with above points?

Cornel_0-1715330587262.png

 

Mathcad Prime 9 fille attached.

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:Cornel)

A1 is quite different from the rest so it has to be treated separately:

Werner_E_0-1715334008430.png

 

View solution in original post

21 REPLIES 21
LucMeekes
23-Emerald III
(To:Cornel)

If it weren't for the weird placement of A1, you could use an integral over the (absolute value of the) function.

So what's left is brute force. like this:

LucMeekes_0-1715331552035.png

Success!
Luc

Cornel
19-Tanzanite
(To:LucMeekes)


@LucMeekes wrote:

If it weren't for the weird placement of A1, you could use an integral over the (absolute value of the) function.


And how A1 should look like in order to be able to use an integral over the (absolute value of the) function?

ttokoro
20-Turquoise
(To:Cornel)

Same with unit.

image.pngimage.pngimage.png

Werner_E
25-Diamond I
(To:Cornel)


@Cornel wrote:

@LucMeekes wrote:

If it weren't for the weird placement of A1, you could use an integral over the (absolute value of the) function.


And how A1 should look like in order to be able to use an integral over the (absolute value of the) function?


That way:

Werner_E_0-1715334695162.png Werner_E_1-1715334424188.png

 

 

Cornel
19-Tanzanite
(To:Werner_E)

I am wondering if this is correct the total area calculation:

Cornel_0-1715339231378.png

 

 

Cornel_4-1715339550775.png


Then how to find this point, the point that cut x aixs, and this point is also the point between x2 and x3 points:

Cornel_0-1715339829511.png

Werner_E
25-Diamond I
(To:Cornel)


@Cornel wrote:

I am wondering if this is correct the total area calculation:


It is, if you really are looking for the sum of the un-oriented (non-negative) areas.

 


Then how to find this point, the point that cut x aixs, and this point is also the point between x2 and x3 points:

 


?? Thats a simple linear equation to solve!

But if you really want Prime to do the job, you may use

Werner_E_0-1715340811357.png

 

Werner_E
25-Diamond I
(To:Cornel)

A1 is quite different from the rest so it has to be treated separately:

Werner_E_0-1715334008430.png

 

Cornel
19-Tanzanite
(To:Werner_E)

And for this?

Cornel_1-1715335285204.png

 

Cornel_0-1715335595907.png

 

Werner_E
25-Diamond I
(To:Cornel)

Cornel
19-Tanzanite
(To:Werner_E)

Right now I wanted to post this, which is like you have posted with your img, and can be used here your forumla:

Cornel_2-1715336453314.png

 

Cornel_1-1715336425064.png



Cornel_0-1715336282653.png
But also your answers for the first posted img was good to know.

 

Werner_E
25-Diamond I
(To:Cornel)

I see that you added the point 0.003 us and 0 V. This is different from the previous data, where we we have had f(0.004 us) = 0 V.

 

Anyway, you now should know how to calculate the areas-sum for any "coloring" you provide 😉

Cornel
19-Tanzanite
(To:Werner_E)

Is it possible to add automatically a in x vector add the position where its fitting in ascending order (x2 then a then x3, as x2>a>x3) and b in y vector at the position where its fitting in ascending order (y2>b>y3), without creating again the 2 vectors and inserting a and b in x and y vectorat the position where x2>a>x3 and y2>b>y3 and without adding a and b at the final of x and y vectors:

Cornel_0-1715342417133.png

 

Werner_E
25-Diamond I
(To:Cornel)


@Cornel wrote:

Is it possible to add automatically a in x vector add the position where its fitting in ascending order (x2 then a then x3, as x2>a>x3) and b in y vector at the position where its fitting in ascending order (y2>b>y3), without creating again the 2 vectors and inserting a and b in x and y vectorat the position where x2>a>x3 and y2>b>y3 and without adding a and b at the final of x and y vectors:

 

 


If the values in vector x are sorted it should be not that difficult.

You could use

xy:=csort(stack(augment(x,y), [a  f(a)]), ORIGIN)

and then separate the two columns in matrix  xy and re-assign them to variables x and y.

 

Cornel
19-Tanzanite
(To:Werner_E)

Ok, I see it works. In this case the x vector is sorted in ascending order from the beginning.

Cornel_0-1715344618646.png

Cornel
19-Tanzanite
(To:Cornel)

@Werner_E 

Only for curiosity at this time, if the x vector is not sorted, what can be done in this case?
Let's say that someone want to add between x2 and x3 a=8 and corresponding in y b = 10, as below example.

Cornel_2-1715345193667.png

Werner_E
25-Diamond I
(To:Cornel)

So this time you not only provide the new values a and b but also the position where you want it inserted.

You could use the "submatrix" function to create a matrix with values before the insertion position and another one with the values below. Then use the "stack" function to assemble them in the correct order.

You may write a utility function insert(value,vector,position) which inserts a given value in a vector at a certain position. If you intend to do so you must be aware that you also must deal with the cases that a value should be inserted at the top or the bottom of the vector. For these two cases you can't use the submatrix function as one of the two matrices would be an empty matrix and unfortunately Prime does not provide that structure (would be a fine feature!). So in these cases you would have to simply stack the new value and the old matrix in the correct order.

 

"submatrix " used to be a slow function so you may also try using a for- loop to create the new vector and add the desired value at the correct position.

Werner_E
25-Diamond I
(To:Werner_E)

OK, forget my last remark about "submatrix" being slow and for-loops may(?) be more efficient. My two attempts with for loops have a calc time which is about 50 times the time the variant with the submatrix command needed (in P4, in P9 and P10 the ratio is even worse) 🙂

 

Find all attached in a Prime 4 worksheet.

 

DJF
16-Pearl
16-Pearl
(To:Cornel)

Just a thought - I'd think that since any solution is going to have the vertices known - you could then use the surveyor formula/shoelace formula to find the area.  A nifty trick Werner taught me years ago that has helped me a lot.

2024-05-10_08-44-04.jpg

 

(OR = origin)

Cornel
19-Tanzanite
(To:DJF)

Hm,,,I to make also the Area(x,y) to give the same answer as Area2 or maybe Area3? Do not know what is the correct answer in this case..

Cornel_4-1715352572816.png


Even if I put like that the answer is different than Area(x,y):

Cornel_6-1715352631825.png

DJF
16-Pearl
16-Pearl
(To:Cornel)

only a guess, but since the shoelace formula closes itself (i.e. back to (0,0) the negative y values act as a negative area - since the lines cross themselves.  But if you define A1, A2, etc as unique closed areas of vertices those areas should give the same values as integrating or other geometry.  Since you have a mix of triangles and rectangles and others, this one formula will suffice once your have the vertices defined.

Werner_E
25-Diamond I
(To:DJF)

The shoelace formula will consider the orientation of the individual areas it calculates and so the result for a self-overlapping polygon as we have it in this example is not as expected.

It would be necessary to split the polygon in two at the point of intersection (x=1595/1589 us which is approx. 1.0038 us).

 

Werner_E_0-1715358656996.png Werner_E_1-1715358718255.png

Werner_E_2-1715359167569.png

 

 

 

Announcements

Top Tags