135 Reputation

5 Badges

0 years, 348 days

MaplePrimes Activity

These are answers submitted by jganding

The commands seem to have worked here but I did have to use the Power[a,b] function to get your Log[x]^2 command entered.  Also, for some reason, I wasn't able to cut and paste your code and have it work.  I typed it all in again and it worked ok.  See if this worksheet gets you going...


Here's another example making extensive use of peicewise differential equations.  Perhaps it could be improved using the events option but am sharing to facilitate learning.  Thanks!


The simplification isn't always the same depending on whether x is positive or negative, real or imaginary.  For example, if Maple doesn't know if x is positive or negative, it may not know how to simplify the expression.  This can be seen in the attached...


This should get you going.  Fixed a few things...

  • removed the list/set braces from your model as they were specified in the dsolve line
  • fixed syntax errors (  := vs = ) and added ; at the end of your "Nilai awal" parameters
  • specified Pi and gamma as local variables since these are protected
  • fixed the syntax of the plot commands' labels option
  • your model uses N(t) but there is no differential equation or functional equavilent (in terms of the other functions) for N(t).  I redefined the model using N(t)=1 and the model runs so you'll need to decide what you want to do with N(t).
  • Maple did not like your function name "I(t)" so I renamed it "It(t)"


If you are willing to parameterize your low and high "x" values, this should work for you.  In the sheet at the link, try different functions and x ranges to test for validity.  In my limited testing, this approach seemed to work well...




proc (x) options operator, arrow, function_assign; sin(x)+9 end proc



loX := -2*Pi; hiX := 3*Pi






plot(f(x), x = loX .. hiX, y = min(0, minimize(f(x), x = loX .. hiX)) .. max(0, maximize(f(x), x = loX .. hiX)))



Download plot_with_y_is_0.mw

Here is a worksheet that does something very similar to what you are asking.  Try this out and let me know if you have questions.


If you can export your MATLAB data into a CSV file, you can import it very easily as shown in the attached Maple worksheet.  You can assign it a name and/or datatype (I use Array in my example number 2).  I've added the column name "Data" in the file.  Of course you will need to replace the file path in the worksheet example with the location of your specific data file.  If the dataset is small, you can also just copy and paste it in like I did in Example 3 though this isn't the best way to do things.  I've also given the pasted data a name (vectorData).  These datasets are indexed (examples shown in the worksheet). Give it a try.


CSV data used in example (this is your data - just cut and paste it into a text file called data.csv): 


Here's some insight.  I see that odeSys as two elements.  When ShootingMethod is called, the first element gets passed as "odeSys" and the 2nd element gets passed as "a".  All arguments then get offset one variable to the right.  This leads to "maxIter" being equated to 0.1.  Therefore, when you define "odeSys", you can put the definition in { } brackets and the variable values don't get shifted one variable name to the right when the procedure is called.  The procedure then fails at the call of "dsolve".  I didn't dive into how the definition of odeSys can be corrected to fix this though.

Define odeSys this way using { }:

odeSys := {diff(u(t), t, t) = u(t)*(diff(v(t), t))^2, diff(v(t), t, t) = -2*u(t)*(diff(u(t), t))*(diff(v(t), t))/(u(t)^2+1)};

and call dsolve this way:

dsolve(odeSys, {u(a) = alpha_u, v(a) = alpha_v, D(u)(a) = du, D(v)(a) = dv},{u(t),v(t)}, numeric,output = listprocedure, range=a..b);

Note the repositioning of the first { bracket after having defined odeSys using { }.

Syntactically this seems correct but Maple doesn't seem to like the way the system of diff eqs are defined with regard to their initial conditions.  I didn't dig further into this but at least this get's you past the issue with maxIter being set to 0.1.

Here is a (messy) version of your file with some print statements added for debugging.  It isn't a final running version top to bottom (i.e., it still has errors) but it does show how odeSys can be kept from shifting argument values one variable to the right.


I see you are working with matrices.  If you are willing to convert to/from arrays, then there are utilities here in Maple's Application Center that can help do what you want to do:


They are fully documented there as well.

Here is an example of how this might work.


I've included the latest version of the utility code right in the file.  As mentioned, the documentation of how to use the utilities is included in the file at the link in the Application Center.


I think what you may have meant to manipulate is

(x-a)2 + 2 a (x-a)

This does simplify to

x- a2


Using printf can make the output a little cleaner and works well as a way to output tabular data.  I did this in the attached file for your solution though I wasn't crystal clear on what you meant by "average forecast".  I printed out all 3 columns of the solution table.  There may be more elegant ways to do this though this method will give you a decent format.  I suggest you read up on the use of printf as a formatting command - it can really help you out when you need clear tabular output.  Also, you wanted whole numbers without decimals.  I took the liberty to round the numbers in the output.  If this is not what you want and you just need to drop the decimals without rounding, change each instance of the "round" command in the printf line to "trunc".  Hope this helps.


Does specifying sigma as an array help you here?  It seems it might give you the results you are looking for.

sigma := Array([2, 4, 0, 6]);

See image below:

There may be more elegant ways to do this but this seems to work.  Just be sure to put the for loop in it's own execution group.  That was the only way I got the max(a) to work (Maple 2018).  Also, this assumes the elements tested are positive.  If there will be negative elements, initialize Array a with really negative numbers (e.g., -1e99).  That way, a typical magnitude negative number can be in the set without returning 0 as the largest element.

test := [1, 2, 3, 4, 5, 6, 7, 10];

testseq := [seq(sum(test[i], i = 1 .. j), j = 1 .. numelems(test))];

a := Array(1 .. 1, 1 .. numelems(test));
               test := [1, 2, 3, 4, 5, 6, 7, 10]
            testseq := [1, 3, 6, 10, 15, 21, 28, 38]
                 a := [0  0  0  0  0  0  0  0]

for i to nops(test) while testseq[i] < 15 do

    a[1, i] := testseq[i]

end do;
                          a[1, 1] := 1
                          a[1, 2] := 3
                          a[1, 3] := 6
                         a[1, 4] := 10





Page 1 of 1