Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X
Hello,
In the attached mathcad sheet, i need to determine the x value at which the function M(x) is maximum, and need the maximum value of the moment function M(x). Thanks!
Solved! Go to Solution.
Mike Armstrong wrote:
Nice Werner, I have to say either the root or Maximize is the way to got though.
Thanks, and yes, I agree. I just added the vector method with max() because this is what sameer obviously was trying to do but failed, because he used a range variable instead of a vector. N=250 as I had set it is too small - this value has at least to be doubled. Furthermore getting the corresponding x-value using match() is not quite "natural".
While I have a slight favor for the derivative way I guess your solve block may be more versatile and probably more robust when we come across more "ill-natured" functions.
Have a look at the attached.
See attached two ways to get what you want.
The first follows the way you tried (don't misuse ranges, use vectors) and the second is an analytical approach using the derivative.
Nice Werner, I have to say either the root or Maximize is the way to got though.
Mike Armstrong wrote:
Nice Werner, I have to say either the root or Maximize is the way to got though.
Thanks, and yes, I agree. I just added the vector method with max() because this is what sameer obviously was trying to do but failed, because he used a range variable instead of a vector. N=250 as I had set it is too small - this value has at least to be doubled. Furthermore getting the corresponding x-value using match() is not quite "natural".
While I have a slight favor for the derivative way I guess your solve block may be more versatile and probably more robust when we come across more "ill-natured" functions.
I do actually like the derivative way, just wasn't clever enough to think of it.
Thank you Mike and Werner for the different good answers. i like the derivative way too. one question i have is when i copied and pasted the solution where you build a vector , it gives me an error about the subscript i in xi equation. the error is" array index is invalid for this array". what could be the reason?
Thank you all again!
Please upload the worksheet to save us guessing.
I have also created a solution using a For Loop within a program. Unfortunately without units, but another solution nevertheless.
Mike Armstrong wrote:
I have also created a solution using a For Loop within a program. Unfortunately without units, but another solution nevertheless.
Nice, but I still would prefer root or maximize.
BTW, as we haven't any constraints we could omit "Given" and use Maximize() standalone, making it even a bit more compact than the root solution.
@sameer: Does it cure your problem if you use i:=ORIGIN..ORIGIN+N instead of i:=0..N ? If yes, you would also have to change the 0 after match() to ORIGIN.
Nicely spotted again.
It was the my first guess here http://communities.ptc.com/message/239539#239539
and sameer even replied to this post of mine (sending the sheet) but obviously had not cheched the sheet for the value of ORIGIN himself.
Hi Werner,
I went to "Tools", "worksheet options", and changed the origin of the array to zero, but the "i" is still in red.i did that before i sent the sheet. is there a different place where i need to change the origin?
where do i change the origin of the array?
Thank you Mike and Werner for all your assistance!
Click Tools, Worksheet Options and check Origin is set to zero.
Mike,
This is what i did. i wish I knew how to insert an image of it to show you. i am attaching the sheet again.Thanks!
Have a look at the attached solution.
I have re-defined ORIGIN using the global definition because it seems ORIGIN is defined within your sheet as 1. I cannot find it so you should look as this will override the top level settings.
Thank you Mike so much!
i was able to find the settings for origin in the sheet by using the tool "Find" to look for the word "origin".
Thanks again!
No problem at all. We got there in the end
Take care! There may be parts of your sheet relying on ORIGIN being set to 1.
Whoever wrote that (global) assignment maybe has meant something by doing it.
I have to agree with Werner (AGAIN ), however most user defined functions and members of the forum work with Origin = 0, so I would reccommend progressing that way.
most user defined functions and members of the forum work with Origin = 0, so I would reccommend progressing that way.
I agree, too .
IMO you really would need a very good reason to change ORIGIN from the default value 0 to something else like 1. But then I see more and more worksheets here with ORIGIN=1, so people seem to feel uncomfortable counting the first element in a vector as number zero.
It may be that just people with some programming background one day begin to think its natural to start counting by zero
Anyway, many user functions people are posting here assume the default (ORIGIN=0) and will not work correctly if copied in a worksheet with a different setting (as we have seen here).
So if you change the value of a system variable, you really should know what you do and what consequences it might have.
Here is the program in Prime which does allow mixed unit arrays..... However, as Prime has taken 1 step forward it isn't quite there.
It defaults to base units and cannot be changed inside the brackets.
The is a workaround but doesn't look quite right. Hopefully this can be ironed out in Prime 4.0.
Being able to use units of different dimensions in one array sure is (even though its not fully implemented as you show) one of the few advantages of Prime over good old Mathcad. But that does't compensate for the many missing features and newly introduced drawbacks. At least not now. Given the way Prime was introduced and the way and speed it "developed" up to version I am not very optimistic about future versions. But I know that you are more enthusiastic and optimistic concerning the future of Prime.
But Prime or real Mathcad, using that kind of brute force maximum lookup gives you as bad results as the methods using max() and the vectors I posted. We would need an extremely fine grid (slowing down calculation) to come close to the precision of the other two methods. Using a step widht of 0.1 obviously will get you a precision of just 1 decimal for x - given that the curve is flat at the top we get a bit better precision for M.
Werner Exinger wrote:
Being able to use units of different dimensions in one array sure is (even though its not fully implemented as you show) one of the few advantages of Prime over good old Mathcad. But that does't compensate for the many missing features and newly introduced drawbacks. At least not now.
A fully appreciate what you are saying, but the faults of Prime have been widely acknowledged throughout this forum, which have clouded the improvement's actually included in Prime.
Given the way Prime was introduced and the way and speed it "developed" up to version I am not very optimistic about future versions. But I know that you are more enthusiastic and optimistic concerning the future of Prime.
I think we have to be, don't we? What other choice do we have except get behind the development of Prime and hope PTC bring a version out which at least covers what is missing from M15.
If Prime would have been brought out with the functionality of M15 and included these new features I believe the majority would be happy.
What other choice do we have except get behind the development of Prime and hope PTC bring a version out which at least covers what is missing from M15.
That depends on the personal situation and company decision. We decided that Prime 12.0 wouldn't be worth waiting for and are beginning to try and test alternatives. Well being aware that it will be not pleasant to throw away a lot of proven worksheets having to write many things new from scratch (not so different if we would stay with Prime). And of course Mathcad doesn't have a clear competitor, concerning the way it works, presents its results, works with units, etc. We sure will give SMath a closer look, but I don't think it will make it. We have concerns the cost factor, of course, employee training, prchase of (mabe even more than one) more expensive software, ... So it was no easy and lighthearted decision, but doing nothing and just hoping that PTC will succeed in bring Prime at least to the level of a 8 year old program version seemed aus to be kind of ostrich approach, putting our heads in the sand. We will continue to use MC15 as long as thats possible and applicable but won't bother with Prime. I see this decision with mixed emotions but on the other hand it really seems to be the only realistic way to go.
If Prime would have been brought out with the functionality of M15 and included these new features I believe the majority would be happy.
Probably, but they have proven not to be able to do so - for whatever reason. And they weren't able to do so up to version 3, not even close! So I see no reason for optimism.
one question i have is when i copied and pasted the solution where you build a vector , it gives me an error about the subscript i in xi equation. the error is" array index is invalid for this array". what could be the reason?
Hard to say without seeing the sheet.
Is the sheet you copied the expression to also using ORIGIN=0 or is it set to something different (likely 1)? A the moment thats the only reason I can think of why the copied expression could fail.
Please see attached. Scroll down until you see the big red arrow. Thank you all!
So its as I suspectd - the value of ORIGIN in your sheet is changed from the default 0 to 1.
So you have to apply the changes as given in my post above.
Have a look at the attached.
So the number of intervals is now N-1 and not N 😉