jganding

135 Reputation

6 Badges

1 years, 152 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...

FromMma_Example.mw

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!

https://www.maplesoft.com/applications/Detail.aspx?id=155115

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...

inverse_test.mw

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)"

diff_eqs_Grafik.mw

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...

restart

``

"f(x):=sin(x)+9;"

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

(1)

NULL

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

-2*Pi

 

3*Pi

(2)

NULL

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.

num_vs_exact_de_soln_(v00).mw

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.

Data_Import_Example.mw

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

   Data
   1.6495e-02
   5.1389e-01
   1.0114e+00
   1.5091e+00
   2.0070e+00
   2.5049e+00
   3.0031e+00
   3.5013e+00
   3.9997e+00
   4.4982e+00
   4.9969e+00
   5.4956e+00
   5.9945e+00
   6.4935e+00
   6.9926e+00
   7.4919e+00
   7.9912e+00
   8.4906e+00
   8.9901e+00
   9.4898e+00
   9.9895e+00
   1.0489e+01
   1.0989e+01
   1.1489e+01
   1.1989e+01
   1.2489e+01
   1.2989e+01
   1.3490e+01
   1.3990e+01
   1.4490e+01

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.

Simple_ODE_Met_1_with_comments.mw

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:

https://www.maplesoft.com/Applications/Detail.aspx?id=155121

They are fully documented there as well.

Here is an example of how this might work.

FindRowInMatrix_with_utilities.mw

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.

Enjoy!

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.

MaplePrimes_TS_Example_w_printf.mw

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.

restart;
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

const:=max(a);
                          const:=10

 

 

 

Page 1 of 1