topic Re: Programming of Simpson's rule in PTC Mathcad
https://community.ptc.com/t5/PTC-Mathcad/Programming-of-Simpson-s-rule/m-p/561994#M181396
<BLOCKQUOTE><HR /><LI-USER uid="291917"></LI-USER> wrote:<BR />
<P>Thank for the answers guys,</P>
<P>So if I use mathcad prime integration, it would be like this. Looks good, or I did something wrong? :=)</P>
</BLOCKQUOTE>
<P>Not sure. If S.n in your sheet is the same as what is calles S.uu in your template, than it seem so be OK.</P>
<P>You had defines S.uu differently in your sheet and so I used the S.uu you defined.</P>
<P> </P>
<P>Do you get a result for M(5) or higher values of n?</P>
<P> </P>
<P>Are you sure that the function which is called S.uu in the picture you show is the same which you call S.n in your sheet and not a function similar to what you call S.uu in your sheet??</P>Fri, 20 Jul 2018 14:47:09 GMTWerner_E2018-07-20T14:47:09ZProgramming of Simpson's rule
https://community.ptc.com/t5/PTC-Mathcad/Programming-of-Simpson-s-rule/m-p/561953#M181389
<P>Team,</P>
<P> </P>
<P>Hope you can help me with one more question. </P>
<P> </P>
<P>I was solving on-bottom stability and I'm stucked on aproximation of the integral of the function. There are many ways how to solve this Trapezoidal rule, SImpson's rule etc.. so any of those would be great (but not sure how to program any of them). </P>
<P><BR />Can you please check this spreadsheet and help me. Basicly I'm not sure how to call for even/uneven numbers based on the defined gamma. </P>
<P><BR />Thank you </P>
<P> </P>
<P>AS</P>Fri, 20 Jul 2018 12:50:54 GMThttps://community.ptc.com/t5/PTC-Mathcad/Programming-of-Simpson-s-rule/m-p/561953#M181389AdoS2018-07-20T12:50:54ZRe: Programming of Simpson's rule
https://community.ptc.com/t5/PTC-Mathcad/Programming-of-Simpson-s-rule/m-p/561965#M181390
<P>Why try to write your own numeric integration approximation (Simpson), when you can have Prime do it for you?</P>
<P>Example:</P>
<P><IMG src="https://sejnu66972.i.lithium.com/t5/image/serverpage/image-id/8827iEF3FAA637E6846FB/image-size/original?v=1.0&px=-1" border="0" alt="LM_20180720_Integrate.png" title="LM_20180720_Integrate.png" /></P>
<P>Success!<BR />Luc</P>
<P> </P>Fri, 20 Jul 2018 13:34:59 GMThttps://community.ptc.com/t5/PTC-Mathcad/Programming-of-Simpson-s-rule/m-p/561965#M181390LucMeekes2018-07-20T13:34:59ZRe: Programming of Simpson's rule
https://community.ptc.com/t5/PTC-Mathcad/Programming-of-Simpson-s-rule/m-p/561976#M181392
<P>Ah, I see. You don't have functions, you have discrete data/vectors (although I guess that's just your doing, you might as well have omega as a running variable and use the Suu function).</P>
<P>Anyway, in case of vector data, integration becomes summation. See if this helps:</P>
<P><IMG src="https://sejnu66972.i.lithium.com/t5/image/serverpage/image-id/8832i894C6DCD86CEDAF3/image-size/original?v=1.0&px=-1" border="0" alt="LM_20180720_Integrate1.png" title="LM_20180720_Integrate1.png" /></P>
<P>Note! It's not complete, I left it for you to finish. But at least it gives you a clue how to get to even and uneven indexed values...</P>
<P> </P>
<P>Success!<BR />Luc</P>Fri, 20 Jul 2018 13:57:03 GMThttps://community.ptc.com/t5/PTC-Mathcad/Programming-of-Simpson-s-rule/m-p/561976#M181392LucMeekes2018-07-20T13:57:03ZRe: Programming of Simpson's rule
https://community.ptc.com/t5/PTC-Mathcad/Programming-of-Simpson-s-rule/m-p/561980#M181393
<P>It wouldn't be hard to implement Simpson but as Luc said its not necessary as Prime would do the job of numeric integration for you if possible.</P>
<P>Unfortunately its not possible with the functions an limits you provide.</P>
<P>You have to evaluate an improper integral (the upper limit is infinity), but the function g(omega), which is part of the integrand, will fail for values of omega greater than 21.8 because of numerical limitation.</P>
<P>Here is a possible workaround using an auxiliary function g_ which is set to zero for omega>21.</P>
<P><IMG src="https://sejnu66972.i.lithium.com/t5/image/serverpage/image-id/8833i69A5D4869D5C613E/image-size/original?v=1.0&px=-1" border="0" alt="B.jpg" title="B.jpg" width="330" height="443" /></P>
<P><IMG src="https://sejnu66972.i.lithium.com/t5/image/serverpage/image-id/8834iE9DD83E058B4DA06/image-size/original?v=1.0&px=-1" border="0" alt="B2.jpg" title="B2.jpg" width="479" height="444" /></P>Fri, 20 Jul 2018 14:01:33 GMThttps://community.ptc.com/t5/PTC-Mathcad/Programming-of-Simpson-s-rule/m-p/561980#M181393Werner_E2018-07-20T14:01:33ZRe: Programming of Simpson's rule
https://community.ptc.com/t5/PTC-Mathcad/Programming-of-Simpson-s-rule/m-p/561988#M181394
<P>Thank for the answers guys,</P>
<P>So if I use mathcad prime integration, it would be like this. Looks good, or I did something wrong? :=)<IMG src="https://sejnu66972.i.lithium.com/t5/image/serverpage/image-id/8836i225BDBEBAFAA7E42/image-size/original?v=1.0&px=-1" border="0" alt="Capture232.JPG" title="Capture232.JPG" /></P>Fri, 20 Jul 2018 14:09:20 GMThttps://community.ptc.com/t5/PTC-Mathcad/Programming-of-Simpson-s-rule/m-p/561988#M181394AdoS2018-07-20T14:09:20ZRe: Programming of Simpson's rule
https://community.ptc.com/t5/PTC-Mathcad/Programming-of-Simpson-s-rule/m-p/561994#M181396
<BLOCKQUOTE><HR /><LI-USER uid="291917"></LI-USER> wrote:<BR />
<P>Thank for the answers guys,</P>
<P>So if I use mathcad prime integration, it would be like this. Looks good, or I did something wrong? :=)</P>
</BLOCKQUOTE>
<P>Not sure. If S.n in your sheet is the same as what is calles S.uu in your template, than it seem so be OK.</P>
<P>You had defines S.uu differently in your sheet and so I used the S.uu you defined.</P>
<P> </P>
<P>Do you get a result for M(5) or higher values of n?</P>
<P> </P>
<P>Are you sure that the function which is called S.uu in the picture you show is the same which you call S.n in your sheet and not a function similar to what you call S.uu in your sheet??</P>Fri, 20 Jul 2018 14:47:09 GMThttps://community.ptc.com/t5/PTC-Mathcad/Programming-of-Simpson-s-rule/m-p/561994#M181396Werner_E2018-07-20T14:47:09ZRe: Programming of Simpson's rule
https://community.ptc.com/t5/PTC-Mathcad/Programming-of-Simpson-s-rule/m-p/562126#M181419
<P>Gents,</P>
<P> </P>
<P>first sorry for late answer. I had weekend far away from the Internet connection ( it was a bit weird, but relaxing).</P>
<P> Thank you the answers. Yes I mixed the functions, I think it should be good now, that little trick with w for over 21.8 worked. </P>
<P>Also for previous solution attached I was not able to calculate M over 5. <BR /><BR />Question is this 21 presents value of w of 21 of position of w 21 which in my case is 0.52?</P>
<P> </P>
<P>Regards</P>
<P> </P>
<P> </P>Mon, 23 Jul 2018 06:44:43 GMThttps://community.ptc.com/t5/PTC-Mathcad/Programming-of-Simpson-s-rule/m-p/562126#M181419AdoS2018-07-23T06:44:43ZRe: Programming of Simpson's rule
https://community.ptc.com/t5/PTC-Mathcad/Programming-of-Simpson-s-rule/m-p/562166#M181420
<BLOCKQUOTE><HR />
<P>Question is this 21 presents value of w of 21 of position of w 21 which in my case is 0.52?</P>
<HR /></BLOCKQUOTE>
<P>Sorry, but i don't understand your question.</P>
<P>Values for w which are greater than approx. 21.84 will make your function g(w) fail because the denominator in the expression you calculate exceeds the numerics limit of approx 10^308. The value of g would be lower than 10^-308 and thats the reason its set to zero for w>21 in the function g_(w)</P>
<P><IMG src="https://sejnu66972.i.lithium.com/t5/image/serverpage/image-id/8883i91BDFA286F879C47/image-size/original?v=1.0&px=-1" border="0" alt="B0.jpg" title="B0.jpg" width="139" height="88" /></P>
<P>But I don't understand what the w in all of your functions and expression should have to do with the vector w you had created. The value with index 21 is 0.52, yes. But the "21" I used as a limit for setting g to 0 is the value of omega itself, not its number in your vector.</P>
<P>BTW - did you typed in that vector omega by hand? All 283 values? As they are equidistant, you could have used something like</P>
<P><IMG src="https://sejnu66972.i.lithium.com/t5/image/serverpage/image-id/8884i414FA15BCD1255C2/image-size/original?v=1.0&px=-1" border="0" alt="B1.jpg" title="B1.jpg" width="347" height="72" /></P>
<P>to create that very same vector.</P>Mon, 23 Jul 2018 08:38:30 GMThttps://community.ptc.com/t5/PTC-Mathcad/Programming-of-Simpson-s-rule/m-p/562166#M181420Werner_E2018-07-23T08:38:30ZRe: Programming of Simpson's rule
https://community.ptc.com/t5/PTC-Mathcad/Programming-of-Simpson-s-rule/m-p/562201#M181423
<P>Hi, </P>
<P> </P>
<P>Thank you for the reply, yes I have typed all by hand, thank you for showing me this trick it is fantastic. And thanks for explaining 21. </P>
<P> </P>
<P>Acctually I do firmly think I made some error with definition of this w All I wanted is to define values of X axis which shall fill Snn(w) function, and this should be multiplied with G(w) Function and used in integral as is. </P>
<P> </P>
<P>That is why I started to write in a vector (first sheet I sent), and use some of approximation rules to calculate M. </P>
<P> </P>
<P><IMG src="https://sejnu66972.i.lithium.com/t5/image/serverpage/image-id/8890i40F1AD65506F84AC/image-size/original?v=1.0&px=-1" border="0" alt="jw.JPG" title="jw.JPG" width="324" height="262" /><IMG src="https://sejnu66972.i.lithium.com/t5/image/serverpage/image-id/8891iCB10F70C4807BFE5/image-size/original?v=1.0&px=-1" border="0" alt="Capture1.JPG" title="Capture1.JPG" /><IMG src="https://sejnu66972.i.lithium.com/t5/image/serverpage/image-id/8892iD4B1D183B0613A51/image-size/original?v=1.0&px=-1" border="0" alt="Capture2.JPG" title="Capture2.JPG" /></P>Mon, 23 Jul 2018 11:03:30 GMThttps://community.ptc.com/t5/PTC-Mathcad/Programming-of-Simpson-s-rule/m-p/562201#M181423AdoS2018-07-23T11:03:30ZRe: Programming of Simpson's rule
https://community.ptc.com/t5/PTC-Mathcad/Programming-of-Simpson-s-rule/m-p/562206#M181424
<P>You don't need to define omega to get a plot of your functions (and if, you'd rather define omega as a range -> w:=0.1,0.12..5.74)</P>
<P>Simple use an undefined w in your plot and change the values at the axis as you need.</P>
<P>For each axis you can change the first, second and last value (as highlighted in the plot screenshot below).</P>
<P>Plot looks different as in your picture (hope I got the correct functions to plot), especially the magnitude on the ordinate. You did not use units so we cannot check for consistency here.</P>
<P><IMG src="https://sejnu66972.i.lithium.com/t5/image/serverpage/image-id/8893i4201243E4F7D7802/image-size/original?v=1.0&px=-1" border="0" alt="B.jpg" title="B.jpg" width="529" height="314" /></P>Mon, 23 Jul 2018 11:21:49 GMThttps://community.ptc.com/t5/PTC-Mathcad/Programming-of-Simpson-s-rule/m-p/562206#M181424Werner_E2018-07-23T11:21:49ZRe: Programming of Simpson's rule
https://community.ptc.com/t5/PTC-Mathcad/Programming-of-Simpson-s-rule/m-p/562209#M181426
<P>Well idea was not to get plot, rather to get value of M0 which I need to calculate velocity Us (last line in the attached sheet). </P>
<P> </P>
<P>But I see the point. Please see attached sheet now with omega defined as a range. nothing works for value of h over 35, but I guess that is due not possibility to iterate. Might assume not so much wave influence at that depth (h is the depth) </P>
<P> </P>
<P>Regards</P>Mon, 23 Jul 2018 11:42:03 GMThttps://community.ptc.com/t5/PTC-Mathcad/Programming-of-Simpson-s-rule/m-p/562209#M181426AdoS2018-07-23T11:42:03ZRe: Programming of Simpson's rule
https://community.ptc.com/t5/PTC-Mathcad/Programming-of-Simpson-s-rule/m-p/562232#M181430
<P>For your purpose you don't need to define omega anyway! There is no need to define values. The range you defined is not used (other than in the plot) anywhere in your sheet. You can delete it.</P>
<P>If you need a series of values for a calculation, you should use a vector.</P>
<P>A range should be used just to index the elements of a vector/matrix, for plotting and in a programmed for-loop.</P>
<P> </P>
<P>For me, the integral already fails for h=33.3 (its the integral, which fails, not any of the solve blocks)</P>
<P><IMG src="https://sejnu66972.i.lithium.com/t5/image/serverpage/image-id/8899i9883EAFFC27D5983/image-size/original?v=1.0&px=-1" border="0" alt="B1.jpg" title="B1.jpg" width="260" height="227" /></P>
<P>Maybe it could be an option to do the integration not up to infinity but rather up to a finite value like 10 or 14:</P>
<P><IMG src="https://sejnu66972.i.lithium.com/t5/image/serverpage/image-id/8900i8599546E9DFBBD02/image-size/original?v=1.0&px=-1" border="0" alt="B1.jpg" title="B1.jpg" width="303" height="240" /></P>
<P>If thats numerically accaptable, you could use a try and catch construct to fall back to that solution only if the integral up to infinity fails:</P>
<P><IMG src="https://sejnu66972.i.lithium.com/t5/image/serverpage/image-id/8901i91833D05BC4710F9/image-size/original?v=1.0&px=-1" border="0" alt="B3.jpg" title="B3.jpg" width="319" height="201" /></P>
<P>You may apply this principle of course also to the function M(n), but obviously you only need the value of M for n=0.</P>Mon, 23 Jul 2018 12:40:29 GMThttps://community.ptc.com/t5/PTC-Mathcad/Programming-of-Simpson-s-rule/m-p/562232#M181430Werner_E2018-07-23T12:40:29ZRe: Programming of Simpson's rule
https://community.ptc.com/t5/PTC-Mathcad/Programming-of-Simpson-s-rule/m-p/562260#M181432
<P>Hi, </P>
<P> </P>
<P>Thank you for the answer and I'm sorry for so many back and forward. Looks that I poorly define what I want to accomplish. </P>
<P> </P>
<P>Yes, I need to use this set of values, they represent frequencies for certain periods of waves. </P>
<P> </P>
<P>When I started (somehow got lost in all this), I defined it with vectors, and used vectorization to get function Suu, </P>
<P> </P>
<P><IMG src="https://sejnu66972.i.lithium.com/t5/image/serverpage/image-id/8908i0CA3CCBC722471D4/image-size/original?v=1.0&px=-1" border="0" alt="Vectorized.JPG" title="Vectorized.JPG" width="417" height="230" /></P>
<P> </P>
<P>But I was not able to solve that M(0) from this function now, and I know it should be simple (not for me). </P>
<P><BR />Regards</P>Mon, 23 Jul 2018 13:16:51 GMThttps://community.ptc.com/t5/PTC-Mathcad/Programming-of-Simpson-s-rule/m-p/562260#M181432AdoS2018-07-23T13:16:51ZRe: Programming of Simpson's rule
https://community.ptc.com/t5/PTC-Mathcad/Programming-of-Simpson-s-rule/m-p/562276#M181433
<P>As I understand it M(n) is defined by an Integral running from 0 to infinity, not the sum of some discrete values?</P>
<P>So M has nothing to do with a couple of omega-values from 0.10 to 5.7 but is calculated by spanning over the full continuous range of omega from 0 to infinity.</P>
<P>Of course you could approximate that integral by summing up the product of every value in S.uu with the constant distance of your omega values (0.02). But I see no point in doing so but maybe I am missing something.</P>
<P><IMG src="https://sejnu66972.i.lithium.com/t5/image/serverpage/image-id/8914iBAF306D18495B4B7/image-size/original?v=1.0&px=-1" border="0" alt="B.jpg" title="B.jpg" width="345" height="182" /></P>
<P>Applying a trapezoid rule or Simpson would make the result only very slightly more accurate (it still would only be an integration from 0.12 to 5.74 and not from 0 to infinity). And it still would mean replacing the good approximation from Mathcads solve block functions and its numeric integration by a bold one.</P>Mon, 23 Jul 2018 14:33:18 GMThttps://community.ptc.com/t5/PTC-Mathcad/Programming-of-Simpson-s-rule/m-p/562276#M181433Werner_E2018-07-23T14:33:18ZRe: Programming of Simpson's rule
https://community.ptc.com/t5/PTC-Mathcad/Programming-of-Simpson-s-rule/m-p/562288#M181435
<P>Here for comparison the results with the same value of h using the functional approach.</P>
<P>What you can see is twofold:</P>
<P>1) The approxamation by simply summing up the rectangles is pretty acurate</P>
<P>2) The 284 special values of omega which you provide have no influence on the outcome - they don't matter.</P>
<P><IMG src="https://sejnu66972.i.lithium.com/t5/image/serverpage/image-id/8916i8522CA1EEF355CE9/image-size/original?v=1.0&px=-1" border="0" alt="B2.jpg" title="B2.jpg" width="442" height="230" /></P>Mon, 23 Jul 2018 14:44:10 GMThttps://community.ptc.com/t5/PTC-Mathcad/Programming-of-Simpson-s-rule/m-p/562288#M181435Werner_E2018-07-23T14:44:10ZRe: Programming of Simpson's rule
https://community.ptc.com/t5/PTC-Mathcad/Programming-of-Simpson-s-rule/m-p/562309#M181439
<P>Hi, </P>
<P> </P>
<P>Thank you for clarifying this to me sir, you are a mathcad genius. </P>
<P> </P>
<P>I need too look into approach and choose which one suits best, but yes this is what I was looking. </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>Mon, 23 Jul 2018 15:20:08 GMThttps://community.ptc.com/t5/PTC-Mathcad/Programming-of-Simpson-s-rule/m-p/562309#M181439AdoS2018-07-23T15:20:08Z