Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X
Hello,
I have these points:
How to calculate each colored area from below plot made with above points?
Mathcad Prime 9 fille attached.
Solved! Go to Solution.
A1 is quite different from the rest so it has to be treated separately:
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:
Success!
Luc
@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?
Same with unit.
@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:
I am wondering if this is correct the total area calculation:
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 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
A1 is quite different from the rest so it has to be treated separately:
@Cornel wrote:
And for this?
Are you sure about A4???
Otherwise the answer would be here: https://community.ptc.com/t5/Mathcad/How-to-calculate-each-colored-area-for-this-graph-made-by-points/m-p/948887/highlight/true#M211719
Right now I wanted to post this, which is like you have posted with your img, and can be used here your forumla:
But also your answers for the first posted img was good to know.
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 😉
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 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.
Ok, I see it works. In this case the x vector is sorted in ascending order from the beginning.
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.
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.
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.
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.
(OR = origin)
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..
Even if I put like that the answer is different than Area(x,y):
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.
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).