Scott03

784 Reputation

10 Badges

19 years, 186 days

MaplePrimes Activity


These are replies submitted by Scott03

For these types of questions, it would be best to contact Maplesoft's Technical Support.

Scott

It looks like you have not set everything as autoexecute.  Make sure you have both the with(DocumentTools) and the parameter declarations in the autoexecute.  Alternatively, you can copy these lines to be within the Code Edit Region.

Scott

It looks like you have not set everything as autoexecute.  Make sure you have both the with(DocumentTools) and the parameter declarations in the autoexecute.  Alternatively, you can copy these lines to be within the Code Edit Region.

Scott

I believe the random variable generator is always starting with the same seed by default, so you will likely get the same numbers from the "Random Number" generator.  To make these numbers more random place a call to randomize() before the Sample call and after the restart call.  This will set the seed for the random number generator depending on the system clock.

Scott

I believe the random variable generator is always starting with the same seed by default, so you will likely get the same numbers from the "Random Number" generator.  To make these numbers more random place a call to randomize() before the Sample call and after the restart call.  This will set the seed for the random number generator depending on the system clock.

Scott

Try this alteration from Erik's code

make_equations := proc(lambda :: positive, max_t :: positive, $)
local
  appearance_times,  # times at which an event appears
  appearance_deltas,  # times between events
  sample_length,  # number of events contemplated
  sample_generator,  # procedure to generate appearance_deltas
  i;  # counter
global x, t; # variables in the resulting equations
  # We start by taking twice as many appearance times as would be necessary if they're all equal to the expected value:
  sample_length := ceil(2*max_t/lambda);
  sample_generator := Statistics:-Sample(Poisson(lambda));
  appearance_deltas := sample_generator(sample_length);
  appearance_times := convert(convert(appearance_deltas^%T,Vector[row]) . Matrix(sample_length, fill=1, shape=triangular[upper]), list);
  while appearance_times[-1] < max_t do
    # Add another sample_length event times (is very unlikely to be necessary, but...)
    appearance_deltas := sample_generator(sample_length);
    appearance_times := [op(appearance_times), convert(convert(appearance_deltas^%T ,Vector[row]). Matrix(sample_length, fill=1, shape=triangular[upper]) +~ appearance_times[-1], list)];
  end do;
  return [x(0) = 0,
    diff(x(t), t) =
      piecewise(t < appearance_times[1], 0,
        seq('(t < appearance_times[i + 1], t - appearance_times[i])', i = 1 .. sample_length - 1),
        t - appearance_times[sample_length])];
end proc;
 

Scott

Try this alteration from Erik's code

make_equations := proc(lambda :: positive, max_t :: positive, $)
local
  appearance_times,  # times at which an event appears
  appearance_deltas,  # times between events
  sample_length,  # number of events contemplated
  sample_generator,  # procedure to generate appearance_deltas
  i;  # counter
global x, t; # variables in the resulting equations
  # We start by taking twice as many appearance times as would be necessary if they're all equal to the expected value:
  sample_length := ceil(2*max_t/lambda);
  sample_generator := Statistics:-Sample(Poisson(lambda));
  appearance_deltas := sample_generator(sample_length);
  appearance_times := convert(convert(appearance_deltas^%T,Vector[row]) . Matrix(sample_length, fill=1, shape=triangular[upper]), list);
  while appearance_times[-1] < max_t do
    # Add another sample_length event times (is very unlikely to be necessary, but...)
    appearance_deltas := sample_generator(sample_length);
    appearance_times := [op(appearance_times), convert(convert(appearance_deltas^%T ,Vector[row]). Matrix(sample_length, fill=1, shape=triangular[upper]) +~ appearance_times[-1], list)];
  end do;
  return [x(0) = 0,
    diff(x(t), t) =
      piecewise(t < appearance_times[1], 0,
        seq('(t < appearance_times[i + 1], t - appearance_times[i])', i = 1 .. sample_length - 1),
        t - appearance_times[sample_length])];
end proc;
 

Scott

If you wnat to use the points from the ODE plot, would the following work for you?

First we start with the commands that you provided to produce the odeplot

restart; with(plots):
sys := diff(f1(t), t) = .5/f2(t), diff(f2(t), t) = sin(t), diff(f3(t)*f4(t), t) = .15, diff(f3(t)/f4(t), t) = .2*f2(t):
init := f1(0) = 1, f2(0) = 1, f3(0) = 1, f4(0) = 1:
F := dsolve({sys, init}, {f1(t), f2(t), f3(t), f4(t)}, numeric):
W := odeplot(F, [[t, f1(t)], [t, f2(t)], [t, f3(t)], [t, f4(t)]], 0 .. 5.5):
display(W);

Next we want to extract all the Arrays containing the data points, combine them and add the headers with the name of each curve.

Temp := map(op, [op(W)]):
TempList := select(type, Temp, Array):
TempList := map(convert, TempList, Matrix):
TempMatrix := ArrayTools:-Concatenate(2, TempList[1][1 .. -1, 1 .. 2], TempList[2][1 .. -1, 2], TempList[3][1 .. -1, 2], TempList[4][1 .. -1, 2]):
TempMatrix := ArrayTools:-Concatenate(1, Vector[row]([t, f1, f2, f3, f4]), TempMatrix):

Now we can save the data that is stored in TempMatrix into the data file

ExportMatrix("C:\\Test\\Mydata.txt", TempMatrix, target = delimited, delimiter = "\t"):

 

Scott
Application Developer
Maplesoft

If you wnat to use the points from the ODE plot, would the following work for you?

First we start with the commands that you provided to produce the odeplot

restart; with(plots):
sys := diff(f1(t), t) = .5/f2(t), diff(f2(t), t) = sin(t), diff(f3(t)*f4(t), t) = .15, diff(f3(t)/f4(t), t) = .2*f2(t):
init := f1(0) = 1, f2(0) = 1, f3(0) = 1, f4(0) = 1:
F := dsolve({sys, init}, {f1(t), f2(t), f3(t), f4(t)}, numeric):
W := odeplot(F, [[t, f1(t)], [t, f2(t)], [t, f3(t)], [t, f4(t)]], 0 .. 5.5):
display(W);

Next we want to extract all the Arrays containing the data points, combine them and add the headers with the name of each curve.

Temp := map(op, [op(W)]):
TempList := select(type, Temp, Array):
TempList := map(convert, TempList, Matrix):
TempMatrix := ArrayTools:-Concatenate(2, TempList[1][1 .. -1, 1 .. 2], TempList[2][1 .. -1, 2], TempList[3][1 .. -1, 2], TempList[4][1 .. -1, 2]):
TempMatrix := ArrayTools:-Concatenate(1, Vector[row]([t, f1, f2, f3, f4]), TempMatrix):

Now we can save the data that is stored in TempMatrix into the data file

ExportMatrix("C:\\Test\\Mydata.txt", TempMatrix, target = delimited, delimiter = "\t"):

 

Scott
Application Developer
Maplesoft

I second pagans suggestion that you write to another folder.  I usually have a folder at C:\Test on my computer that I write to with my Maple worksheet.  The added bonus is that this folder is at the base of the C drive so it doesn't require me to type so much to specify the location or too many clicks to get there from the windows explorer.  This also gives you one folder that you can highlight everything and delete the files without needing to worry if it is a program file.

As for your question Christopher, have you taken a look at the folder you are trying to write to?  You are trying to write a file called "data" into the Maple folder that already has a folder named "data".


Scott

I second pagans suggestion that you write to another folder.  I usually have a folder at C:\Test on my computer that I write to with my Maple worksheet.  The added bonus is that this folder is at the base of the C drive so it doesn't require me to type so much to specify the location or too many clicks to get there from the windows explorer.  This also gives you one folder that you can highlight everything and delete the files without needing to worry if it is a program file.

As for your question Christopher, have you taken a look at the folder you are trying to write to?  You are trying to write a file called "data" into the Maple folder that already has a folder named "data".


Scott

If you follow Robert's suggestion of calling dsolve you will get everything you will want.  By entering the following:

X := Array([seq(x, x = -5 .. 2, 0.1e-2)]):
S := dsolve({y(0) = 1, (D(y))(x) = y(x)}, type = numeric, output = X):

The Array X has the x values for your equation to be solved at (in your example you would use t instead of x.  The result S would have the output points at S[2,1] with the column names being stored at S[1,1].  Therefore, if you want to output all of that in one file you could do something like the following:

M1 := ArrayTools:-Concatenate(1, S[1, 1], S[2, 1]):
ExportMatrix("C:\\Test\\Mydata.txt", M1, target = delimited, delimiter = "\t");

The Concatenate function can be used to add the column names to the points.

Scott
Application Developer
Maplesoft

If you follow Robert's suggestion of calling dsolve you will get everything you will want.  By entering the following:

X := Array([seq(x, x = -5 .. 2, 0.1e-2)]):
S := dsolve({y(0) = 1, (D(y))(x) = y(x)}, type = numeric, output = X):

The Array X has the x values for your equation to be solved at (in your example you would use t instead of x.  The result S would have the output points at S[2,1] with the column names being stored at S[1,1].  Therefore, if you want to output all of that in one file you could do something like the following:

M1 := ArrayTools:-Concatenate(1, S[1, 1], S[2, 1]):
ExportMatrix("C:\\Test\\Mydata.txt", M1, target = delimited, delimiter = "\t");

The Concatenate function can be used to add the column names to the points.

Scott
Application Developer
Maplesoft

How about using this call?

Matrix(3, 3, RandomTools:-Generate(distribution(Normal(0, 1)), makeproc = true), shape = hermitian);

This uses the shape option to make the matrix the correct shape that you are looking for.

 

Scott

How about using this call?

Matrix(3, 3, RandomTools:-Generate(distribution(Normal(0, 1)), makeproc = true), shape = hermitian);

This uses the shape option to make the matrix the correct shape that you are looking for.

 

Scott

1 2 3 4 5 6 7 Last Page 2 of 20