<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic ODE's error with if else function in Mathcad</title>
    <link>https://www.ptcusercommunity.com/t5/Mathcad/ODE-s-error-with-if-else-function/m-p/1053415#M220441</link>
    <description>&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;I am solving a system of 1D steady ODEs in Mathcad using RK4. The system works correctly until I add a heat transfer term representing two-way coupling between a gas phase and injected droplets. When this term is included, the solver no longer outputs results and reports that the gradient matrix must be scalar or a matrix.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;The gas stagnation temperature gradient&amp;nbsp;&lt;/FONT&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;depends on Reynolds number, Nusselt number and a convective heat transfer coefficient that is itself a function of the ODE variables, which vary along z (length of nozzle)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;All other gradients (Mach, pressure, velocity, etc.) are functions of the same state vector and work correctly when the heat term is removed. I suspect I am incorrectly defining a function within the gradient matrix or using If else wrong.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Any help would be appreciated, as I'm going round in circles.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;below is screenshot of part of code:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MC_14395780_3-1770047934724.png" style="width: 400px;"&gt;&lt;img src="https://www.ptcusercommunity.com/t5/image/serverpage/image-id/134239i45DE62DFA0412613/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MC_14395780_3-1770047934724.png" alt="MC_14395780_3-1770047934724.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MC_14395780_0-1770047771623.png" style="width: 400px;"&gt;&lt;img src="https://www.ptcusercommunity.com/t5/image/serverpage/image-id/134236iCD8A39CBD2331CBF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MC_14395780_0-1770047771623.png" alt="MC_14395780_0-1770047771623.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MC_14395780_1-1770047833792.png" style="width: 400px;"&gt;&lt;img src="https://www.ptcusercommunity.com/t5/image/serverpage/image-id/134237iE11E0750AC4895D0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MC_14395780_1-1770047833792.png" alt="MC_14395780_1-1770047833792.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MC_14395780_2-1770047863631.png" style="width: 400px;"&gt;&lt;img src="https://www.ptcusercommunity.com/t5/image/serverpage/image-id/134238i018F8782F8575E50/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MC_14395780_2-1770047863631.png" alt="MC_14395780_2-1770047863631.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks very much&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 02 Feb 2026 18:01:40 GMT</pubDate>
    <dc:creator>MC_14395780</dc:creator>
    <dc:date>2026-02-02T18:01:40Z</dc:date>
    <item>
      <title>ODE's error with if else function</title>
      <link>https://www.ptcusercommunity.com/t5/Mathcad/ODE-s-error-with-if-else-function/m-p/1053415#M220441</link>
      <description>&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;I am solving a system of 1D steady ODEs in Mathcad using RK4. The system works correctly until I add a heat transfer term representing two-way coupling between a gas phase and injected droplets. When this term is included, the solver no longer outputs results and reports that the gradient matrix must be scalar or a matrix.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;The gas stagnation temperature gradient&amp;nbsp;&lt;/FONT&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;depends on Reynolds number, Nusselt number and a convective heat transfer coefficient that is itself a function of the ODE variables, which vary along z (length of nozzle)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;All other gradients (Mach, pressure, velocity, etc.) are functions of the same state vector and work correctly when the heat term is removed. I suspect I am incorrectly defining a function within the gradient matrix or using If else wrong.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Any help would be appreciated, as I'm going round in circles.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;below is screenshot of part of code:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MC_14395780_3-1770047934724.png" style="width: 400px;"&gt;&lt;img src="https://www.ptcusercommunity.com/t5/image/serverpage/image-id/134239i45DE62DFA0412613/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MC_14395780_3-1770047934724.png" alt="MC_14395780_3-1770047934724.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MC_14395780_0-1770047771623.png" style="width: 400px;"&gt;&lt;img src="https://www.ptcusercommunity.com/t5/image/serverpage/image-id/134236iCD8A39CBD2331CBF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MC_14395780_0-1770047771623.png" alt="MC_14395780_0-1770047771623.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MC_14395780_1-1770047833792.png" style="width: 400px;"&gt;&lt;img src="https://www.ptcusercommunity.com/t5/image/serverpage/image-id/134237iE11E0750AC4895D0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MC_14395780_1-1770047833792.png" alt="MC_14395780_1-1770047833792.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MC_14395780_2-1770047863631.png" style="width: 400px;"&gt;&lt;img src="https://www.ptcusercommunity.com/t5/image/serverpage/image-id/134238i018F8782F8575E50/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MC_14395780_2-1770047863631.png" alt="MC_14395780_2-1770047863631.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks very much&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Feb 2026 18:01:40 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/Mathcad/ODE-s-error-with-if-else-function/m-p/1053415#M220441</guid>
      <dc:creator>MC_14395780</dc:creator>
      <dc:date>2026-02-02T18:01:40Z</dc:date>
    </item>
    <item>
      <title>Re: ODE's error with if else function</title>
      <link>https://www.ptcusercommunity.com/t5/Mathcad/ODE-s-error-with-if-else-function/m-p/1053427#M220443</link>
      <description>&lt;P&gt;How about posting the worksheet itself instead of just pictures? And clarifying exactly which added term made the system fail.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I noticed is that in your definitions of some grad... functions you divide by x7(y1) and in the vector x you provide x7 is zero.&lt;/P&gt;
&lt;P&gt;Furthermore it looks like x8(T01) never is used, but I may have overlooked it in the pictures.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Feb 2026 17:12:46 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/Mathcad/ODE-s-error-with-if-else-function/m-p/1053427#M220443</guid>
      <dc:creator>Werner_E</dc:creator>
      <dc:date>2026-02-02T17:12:46Z</dc:date>
    </item>
    <item>
      <title>Re: ODE's error with if else function</title>
      <link>https://www.ptcusercommunity.com/t5/Mathcad/ODE-s-error-with-if-else-function/m-p/1053453#M220449</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have now added the file above. I have removed x8 (T01) from the vector, and changed y1 (x7) to 0.1.&lt;/P&gt;&lt;P&gt;I think it may be something to do with my if else statement but I can't spot the mistake.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Feb 2026 18:03:58 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/Mathcad/ODE-s-error-with-if-else-function/m-p/1053453#M220449</guid>
      <dc:creator>MC_14395780</dc:creator>
      <dc:date>2026-02-02T18:03:58Z</dc:date>
    </item>
    <item>
      <title>Re: ODE's error with if else function</title>
      <link>https://www.ptcusercommunity.com/t5/Mathcad/ODE-s-error-with-if-else-function/m-p/1053483#M220450</link>
      <description>&lt;P&gt;You can use Prime's error trace facility to trace back to the position the error shows up first.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your case it traces back to the call of function F.drag.&lt;/P&gt;
&lt;P&gt;You defined F.drag as a function with two arguments&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Werner_E_0-1770059833561.png" style="width: 400px;"&gt;&lt;img src="https://www.ptcusercommunity.com/t5/image/serverpage/image-id/134265i02CC58392353BC79/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Werner_E_0-1770059833561.png" alt="Werner_E_0-1770059833561.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;but you call it with just one argument&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Werner_E_1-1770059873172.png" style="width: 540px;"&gt;&lt;img src="https://www.ptcusercommunity.com/t5/image/serverpage/image-id/134266iE1D7EA6077F9C3DD/image-dimensions/540x166?v=v2" width="540" height="166" role="button" title="Werner_E_1-1770059873172.png" alt="Werner_E_1-1770059873172.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;The error message tells you exactly that &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Same problem with function C.d&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Werner_E_2-1770060019135.png" style="width: 400px;"&gt;&lt;img src="https://www.ptcusercommunity.com/t5/image/serverpage/image-id/134267i6EE6AACB60F9FA2F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Werner_E_2-1770060019135.png" alt="Werner_E_2-1770060019135.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Unfortunately fixing this&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Werner_E_3-1770060342680.png" style="width: 677px;"&gt;&lt;img src="https://www.ptcusercommunity.com/t5/image/serverpage/image-id/134268i41A0AAE109277EA1/image-dimensions/677x188?v=v2" width="677" height="188" role="button" title="Werner_E_3-1770060342680.png" alt="Werner_E_3-1770060342680.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;don't help for rkfixed.&lt;/P&gt;
&lt;P&gt;It looks like the results do not depend much on z. The results are the same for z=0 and z=L.e=0.5.&lt;BR /&gt;Are the values expected to that high? (10^11)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which was omitted when the system finally worked OK? What was added causing the problem?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Feb 2026 19:44:31 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/Mathcad/ODE-s-error-with-if-else-function/m-p/1053483#M220450</guid>
      <dc:creator>Werner_E</dc:creator>
      <dc:date>2026-02-02T19:44:31Z</dc:date>
    </item>
    <item>
      <title>Re: ODE's error with if else function</title>
      <link>https://www.ptcusercommunity.com/t5/Mathcad/ODE-s-error-with-if-else-function/m-p/1053488#M220451</link>
      <description>&lt;P&gt;I replaced gradT.dr and grady by&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Werner_E_0-1770060851296.png" style="width: 400px;"&gt;&lt;img src="https://www.ptcusercommunity.com/t5/image/serverpage/image-id/134269i7D7BBDB874473658/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Werner_E_0-1770060851296.png" alt="Werner_E_0-1770060851296.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;and I still get the same error in rkfixed ('this function cannot be used here').&lt;/P&gt;
&lt;P&gt;So it looks that the problem are not the if..else..&lt;/P&gt;
&lt;P&gt;Is it on purpose that these function are independent from z?&lt;/P&gt;</description>
      <pubDate>Mon, 02 Feb 2026 19:36:23 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/Mathcad/ODE-s-error-with-if-else-function/m-p/1053488#M220451</guid>
      <dc:creator>Werner_E</dc:creator>
      <dc:date>2026-02-02T19:36:23Z</dc:date>
    </item>
    <item>
      <title>Re: ODE's error with if else function</title>
      <link>https://www.ptcusercommunity.com/t5/Mathcad/ODE-s-error-with-if-else-function/m-p/1059084#M220740</link>
      <description>&lt;P&gt;Hi &lt;SPAN style="background: var(--ck-color-mention-background); color: var(--ck-color-mention-text);"&gt;&lt;a href="https://www.ptcusercommunity.com/t5/user/viewprofilepage/user-id/1023626"&gt;@MC_14395780&lt;/a&gt;&lt;/SPAN&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I wanted to see if you got the help you needed.&lt;/P&gt;
&lt;P&gt;If so, please mark the appropriate reply as the Accepted Solution. It will help other members who may have the same question.&lt;BR /&gt;Please note that industry experts also review the replies and may eventually accept one of them as solution on your behalf.&lt;BR /&gt;Of course, if you have more to share on your issue, please pursue the conversation.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;BR /&gt;Anurag&lt;/P&gt;</description>
      <pubDate>Wed, 18 Mar 2026 10:57:30 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/Mathcad/ODE-s-error-with-if-else-function/m-p/1059084#M220740</guid>
      <dc:creator>anursingh</dc:creator>
      <dc:date>2026-03-18T10:57:30Z</dc:date>
    </item>
  </channel>
</rss>

