mmcdara

867 Reputation

13 Badges

3 years, 233 days

MaplePrimes Activity


These are answers submitted by mmcdara

Reply to question 2 only

I don't know if Maple is capable to transform the Table of my previous post ???
What I use to do is to generate a LaTeX source file directly by writting LaTeX in Maple under text form and saving it to a text file with fprintf commands.
Of course that method needs you to know LaTeX.

PS : in your simple case you could write this directly in a LateX source file.

The only thing to know is that you must protect some special characters : \, {, —, &, and probably a few more.
To do this just type \\, \{, \}, \& ... instead.

Here is something that should do the job (if I didn't make typos).
Unfortunately I don't have any operational LaTeX installation toght now to verify this, but if you have one just copy the content of the file "LatexFile.txt" into your own LaTeX source and compile it.


 

restart:

file := cat(currentdir(), "/desktop/LatexFile.txt"):

fd := fopen(file, WRITE);

0

(1)

ToWrite := cat("\\begin\{tabular\}{|", seq("c|", k=1..7), "\}"):
fprintf(fd, "%s\n", ToWrite):

ToWrite := "\\hline":
fprintf(fd, "%s\n", ToWrite):

ToWrite := cat("x \& ", seq(cat("\\multicolumn\{2\}\{c|\}\{t_", k, " = ", evalf((2*k-1)/3), "\}\&"), k=1..3)):
fprintf(fd, "%s\n", cat(ToWrite[1..-2], "\\\\")):

ToWrite := "\\cline\{2-7}":
fprintf(fd, "%s\n", ToWrite):

ToWrite := cat(seq(cat(" f(x,t) \& g(x,t) \&"), k=1..3)):
fprintf(fd, "%s\n", cat(ToWrite[1..-2], "\\\\")):


for k from 1 to 3 do
   ToWrite := cat("x_", k, " = ", evalf((2*k-1)/3), seq(" \& ", j=1..5), "\\\\"):
   fprintf(fd, "%s\n", ToWrite):
   ToWrite := "\\hline":
   fprintf(fd, "%s\n", ToWrite):
end do:

ToWrite := "\\end\{tabular\}":
fprintf(fd, "%s\n", ToWrite):

 

fclose(file):
fd := fopen(file, READ);

line := readline(fd):
while line <> 0 do
   printf("%s\n", line):
   line := readline(file):
end do:

fclose(file);

0

 

\begin{tabular}{|c|c|c|c|c|c|c|}
\hline
x & \multicolumn{2}{c|}{t_1 = .3333333333}&\multicolumn{2}{c|}{t_2 = 1.}&\multicolumn{2}{c|}{t_3 = 1.666666667}\\
\cline{2-7}
 f(x,t) & g(x,t) & f(x,t) & g(x,t) & f(x,t) & g(x,t) \\
x_1 = .3333333333 &  &  &  &  & \\
\hline
x_2 = 1. &  &  &  &  & \\
\hline
x_3 = 1.666666667 &  &  &  &  & \\
\hline
\end{tabular}

 

 


 

Download DocumentTools[Layout]_2_LaTeX.mw

Reply to question 1 only

Look to the attached file and customize it as you want (PS : the output of the last command cannot be loaded on this site)

 

restart:

with(DocumentTools):

with(DocumentTools[Layout]):

T := Table(
       seq(Column(), k=2..7), widthmode=percentage, width=60, alignment=center,
       Row(
            Cell("x", rowspan=2, padding=20),
            Cell(Textfield(style=TwoDimOutput, Equation(t[1]=evalf[5](1/3))), columnspan=2),
            Cell(Textfield(style=TwoDimOutput, Equation(t[2]=1)), columnspan=2),
            Cell(Textfield(style=TwoDimOutput, Equation(t[3]=evalf[5](5/3))), columnspan=2)
       ),
       Row(
            seq(
                 op([
                      Cell(Textfield(style=TwoDimOutput, Equation(f(x(t))))),
                      Cell(Textfield(style=TwoDimOutput, Equation(g(x(t)))))
                 ]),
                 k=1..3
            )
       ),
       seq(
         Row(
            Cell(Textfield(style=TwoDimOutput, Equation((t[1]=evalf[5](k/3))))),
            seq(Cell(" "), j=1..6)
         ), k in [1, 3, 5]
       )
     ):

InsertContent(Worksheet(Group(Input( T )))):

 


 

Download DocumentTools[Layout].mw

The equation is of the form Y=A*D1+B.

solve(subs(Y=Z*D1, Y=A*D1+B), Z)

This can also be done by using freeze/thaw (see help page),  or by writting 
solve(Y=A*D1+B, Y)/D1

 

Is it something like that you are looking for? 

1/ two sets of hatches of different orientations


2/ filling the red shape with blue squares


3/ Mosaic



This works only for simple polygons (two distinct sides either have no common point or either one common vertex).
In cases 2&3 the filling pattern can be (presently) any convex shape.

I don't understant what you want to do but I've fixed a lot errors in yout code.
I suggest that you read the attached file and continue to correct it yourself.


 

restart:

with(plots):    # You must load this package too

with(DiscreteTransforms);

Digits := 600;

ss := 1:

windowlength := 50:

ma := []:

me := []:

counter1 := 1:

Z := Vector(windowlength, datatype = complex[8]);

Z5 := []:
for i from windowlength+ss to 1+ss by -1 do
  eq2 := x:                  # what's the need to define eq2?

  eq2a := x*2:               

  god := solve(eq2a=y, x);   # your original code was solve(eq2a=y, t);
                             # but t is not in the eqyuation to solve !

  ma := [ma[], evalf(subs(x=100, eq2a))]:

  me := [op(me), 100]:       # could have been written mor simply by setting
                             # me := [100$windowlength] ourside of the loop

  Z[counter1] := ma[-1]+0*I; # What's the meaning to add a null imaginary part ?

  counter1 := counter1 + 1:

od:

Z2 := FourierTransform(Z);

"[[Typesetting:-mi("DiscreteWaveletTransform",italic = "true",mathvariant = "italic"), Typesetting:-mi("FourierTransform",italic = "true",mathvariant = "italic"), Typesetting:-mi("InverseDiscreteWaveletTransform",italic = "true",mathvariant = "italic"), Typesetting:-mi("InverseFourierTransform",italic = "true",mathvariant = "italic"), Typesetting:-mi("WaveletCoefficients",italic = "true",mathvariant = "italic"), Typesetting:-mi("WaveletPlot",italic = "true",mathvariant = "italic")]]"

 

Digits := 600

 

Z := Vector(4, {(1) = ` 1 .. 50 `*Vector[column], (2) = `Data Type: `*complex[8], (3) = `Storage: `*rectangular, (4) = `Order: `*Fortran_order})

 

Vector[column](%id = 18446744078264016758)

(1)

Z5 := []:

for i from 1 to counter1-1 do

  Z5 := [op(Z5),Re(Z2[i])]:

od:

p := dualaxisplot(listplot(Z, color = red), listplot(me, color = blue), style = line, gridlines = false):

p3 := dualaxisplot(listplot(ma, color = red), listplot(me, color = blue), style = line, gridlines = false):

display(p, p3)

 

 


 

Download fft.mw

Simpler with Optimization:-Minimize

Example (use your own epsfunc):
(note the initial point should verify the constraint)
The "log" is a trick I used because obj ~ 10^143 for the initial point, wich results in a "no improved point could be found" error message

epsfunc := t -> a*exp(b*t)+c:
obj  := unapply(log(add((epsfunc~(X) -~ Y)^~2)), [a, b, c]):
sol  := Optimization:-Minimize(obj(a, b, c), {a+b+c=1}, initialpoint={a = 1/3, b = 1/3, c = 1/3});

  sol := [0.0497019913114570486, [a = 1.0387857063266068,  b = -0.022019531897248847, c = -0.01676617442935826)]]

eval(obj(a, b, c), sol[2]);
0.0497019913114570



Another possibility is to use NonLinearFit, not with model epsfunc, but with model 
new_epsfunc := subs(c=1-a-b, epsfunc).

Without knowing what your problem really is, it's not easy to give it a pertinent answer.
You speak of Fourier Transform: why such an idea ? Do you want to filter in the frequency domain ?

Maybe there are other possibilities...
Here is one (for a particuar case that maybe [surely] doesn't correspond at all to your problem of interest).
Let f(x) function.
The idea is to solve numerically a trivial differential equation diff(F(x), x)=diff(f(x),x) with respect to F(x), by using a method with adaptive x-steps. 
I choosed here the rkf45 method but a few others can be used.
The method estimates the local x-step from the quickness diff(f(x), x) changes.
This defines a sequence of unequally spaced x values, all the more sparse that f(x) is flat.

Here are some results.
Maybe it will be useful for you?


 

restart:

f := x -> x^10

proc (x) options operator, arrow; x^10 end proc

(1)

p := plot(f(x), x=-1..1, style=point):
plots:-display(p);
q := plottools:-getdata(p)[-1];

 

Matrix(%id = 18446744078119104374)

(2)

# N := numelems(q[..,1]);
# a := (q[2..N, 1] +~ q[1..N-1, 1]) /~ 2:
# b := (q[2..N, 2] -~ q[1..N-1, 2]):
# plot(a, b, style=point)

# The art to search for noon at fourteen

g := dsolve({diff(F(x), x)=diff(f(x), x), F(-1)=f(-1)}, numeric, method=rkf45, range=-1..1, output=piecewise):

# number of extremity points (here 45 instead of 202 in the ordinary plot)
ni := ( nops(rhs(g[2])) - 1) / 2;

bounds := [ seq(rhs(op(2*i-1, rhs(g[2]))), i=1..ni) ]:

plot(bounds, f~(bounds), style=point);

# plot the x steps

a := (bounds[2..ni] +~ bounds[1..ni-1]) /~ 2:
b := (bounds[2..ni] -~ bounds[1..ni-1]):
plot(a, b, style=point)

45

 

 

 

# same thing but with a larger absolute error

g := dsolve({diff(F(x), x)=diff(f(x), x), F(-1)=f(-1)}, numeric, method=rkf45, range=-1..1, output=piecewise, abserr=1e-4):

# number of extremity points (here 45 instead of 202 in the ordinary plot)

ni := ( nops(rhs(g[2])) - 1) / 2;

bounds := [ seq(rhs(op(2*i-1, rhs(g[2]))), i=1..ni) ]:

plot(bounds, f~(bounds), style=point);

# plot the x steps

a := (bounds[2..ni] +~ bounds[1..ni-1]) /~ 2:
b := (bounds[2..ni] -~ bounds[1..ni-1]):
plot(a, b, style=point)

15

 

 

 

# What you must take is the x coordinates (=bounds) nor the values of F~(bounds)
# because of the possibly large errors

plots:-display(
   plot(f(x), x=-1..1, color=blue, legend='f'),
   plot(bounds, f~(bounds), style=point, color=red, symbol=cross, symbolsize=20, legend = "f sampled")
);

 

 


 

Download A_NoFourier_possibility.mw

Suppose you have a signal s = < 1, 2, ...10 > and another one, t, such that t=s
Compute by hand the cross-correlation of s and t.
I guess you expect that SignalProcessing:-CrossCorrelation and/or Statistics:-CrossCorrelation
will give the same result you have obtained by hand.

To be clear, for a lag=0, the cross correlation should be 12+...102 = 385.
Next, for a lag > 10, the question is "how" the signals are extend out of their support ? Periodically or by zeroes ?
If they are extended by zeroes, then the cross correlation is 0 for lags > 10.
If they are periodically replicated, well, I let you do the math.

Now look to the piece of code I provide and make your choice... or write your own cross correlation product.
Look to the last column of the first example to see the scaling and the shifting (wich is clearly said in the help page of Statistics:-CrossCorrelation).
Look to the zeroes in the first column which means SignalProcessing:-CrossCorrelation extends signals by zeroes.

A last advidce: read carefullly the two help pages.
 

restart

s := Array(1..10, [$1..10]):
t := copy(s):

spc := CodeTools:-Usage(SignalProcessing:-CrossCorrelation(s, t));
sc := CodeTools:-Usage(Statistics:-CrossCorrelation(s, t));

printf("  spc        sc      sc*spc[1]\n");
for n from 1 to 19 do
  printf("%+4.3f    %+4.3f    %+4.3f\n", spc[n], sc[n], sc[n]*spc[1])
end do;

memory used=3.87KiB, alloc change=0 bytes, cpu time=0ns, real time=0ns, gc time=0ns

 

spc := Vector(4, {(1) = ` 1 .. 19 `*Array, (2) = `Data Type: `*float[8], (3) = `Storage: `*rectangular, (4) = `Order: `*Fortran_order})

 

memory used=508.34KiB, alloc change=0 bytes, cpu time=7.00ms, real time=6.00ms, gc time=0ns

 

Vector[column](%id = 18446744078332787758)

 

  spc        sc      sc*spc[1]
+385.000    +0.026    +10.000
+330.000    +0.075    +29.000
+276.000    +0.145    +56.000
+224.000    +0.234    +90.000
+175.000    +0.338    +130.000
+130.000    +0.455    +175.000
+90.000    +0.582    +224.000
+56.000    +0.717    +276.000
+29.000    +0.857    +330.000
+10.000    +1.000    +385.000
+0.000    +0.857    +330.000
+0.000    +0.717    +276.000
+0.000    +0.582    +224.000
+0.000    +0.455    +175.000
+0.000    +0.338    +130.000
+0.000    +0.234    +90.000
+0.000    +0.145    +56.000
+0.000    +0.075    +29.000
+0.000    +0.026    +10.000

 

t := s[1..5]:

spc := CodeTools:-Usage(SignalProcessing:-CrossCorrelation(s, t));
sc := CodeTools:-Usage(Statistics:-CrossCorrelation(s, t));

printf("  spc        sc\n");
for n from 1 to 19 do
  if n <= 14 then
    printf("%+3.3f    %+3.3f\n", spc[n], sc[n])
  else
    printf("          %+3.3f\n", sc[n])
  end if:
end do;

memory used=3.82KiB, alloc change=0 bytes, cpu time=0ns, real time=1000.00us, gc time=0ns

 

spc := Vector(4, {(1) = ` 1 .. 14 `*Array, (2) = `Data Type: `*float[8], (3) = `Storage: `*rectangular, (4) = `Order: `*Fortran_order})

 

memory used=501.98KiB, alloc change=0 bytes, cpu time=7.00ms, real time=6.00ms, gc time=0ns

 

Vector[column](%id = 18446744078332796190)

 

  spc        sc
+55.000    +0.182
+40.000    +0.527
+26.000    +1.018
+14.000    +1.636
+5.000    +2.364
+0.000    +2.091
+0.000    +1.818
+0.000    +1.545
+0.000    +1.273
+0.000    +1.000
+0.000    +0.727
+0.000    +0.473
+0.000    +0.255
+0.000    +0.091
          +0.000
          +0.000
          +0.000
          +0.000
          +0.000

 

t := Array(1..10, [1$10]):
a := s +~ t *~I;
b := s -~ t *~I;
spc := CodeTools:-Usage(SignalProcessing:-CrossCorrelation(s, t));
sc  := CodeTools:-Usage(Statistics:-CrossCorrelation(s, t));

printf("  spc        sc\n");
for n from 1 to 19 do
  printf("%+4.3f    %+4.3f\n", spc[n], sc[n])
end do;

a := Matrix(1, 10, {(1, 1) = 1+I, (1, 2) = 2+I, (1, 3) = 3+I, (1, 4) = 4+I, (1, 5) = 5+I, (1, 6) = 6+I, (1, 7) = 7+I, (1, 8) = 8+I, (1, 9) = 9+I, (1, 10) = 10+I})

 

b := Matrix(1, 10, {(1, 1) = 1-I, (1, 2) = 2-I, (1, 3) = 3-I, (1, 4) = 4-I, (1, 5) = 5-I, (1, 6) = 6-I, (1, 7) = 7-I, (1, 8) = 8-I, (1, 9) = 9-I, (1, 10) = 10-I})

 

memory used=3.87KiB, alloc change=0 bytes, cpu time=0ns, real time=0ns, gc time=0ns

 

spc := Vector(4, {(1) = ` 1 .. 19 `*Array, (2) = `Data Type: `*float[8], (3) = `Storage: `*rectangular, (4) = `Order: `*Fortran_order})

 

memory used=508.70KiB, alloc change=0 bytes, cpu time=7.00ms, real time=7.00ms, gc time=0ns

 

Vector[column](%id = 18446744078332790894)

 

  spc        sc
+55.000    +0.182
+45.000    +0.345
+36.000    +0.491
+28.000    +0.618
+21.000    +0.727
+15.000    +0.818
+10.000    +0.891
+6.000    +0.945
+3.000    +0.982
+1.000    +1.000
+0.000    +0.818
+0.000    +0.655
+0.000    +0.509
+0.000    +0.382
+0.000    +0.273
+0.000    +0.182
+0.000    +0.109
+0.000    +0.055
+0.000    +0.018

 

 


 

Download Signal_or_Stat.mw

 

A complicated solution


 

restart:

f := proc(a)
  local b, l, c:
   b := StringTools:-Split(sprintf("%1.10e", a), "e")[1];
   l := length(StringTools:-Split(b, ".")[2]);
   c := 1:
   while b[-c] = "0" do
      c := c+1:
   end do:
   c := c-1;
   print(evalf[l-c+1](parse(b)))
end proc:

f(2.55*10^(-90))

2.55

(1)

f(-2.55*10^(-90))

-2.55

(2)

 


 

Download Asolution.mw

@weidade37211 

If I'm not mistaken (?) the value of seems to be around 0.13713...
I obtain this same value for Digits = 8, 10, 15

abcd.mw

I didn't know about ColumnGraph (thanks @Carl Love ).
Here is an alternative using Histogram


WithHistogram.mw

 

Just a little thing do do: place the plot command AFTER the if block.

The reason is: plot must be the return of procedure work (just as for any other procedure).
 

Download answer.mw

 

An alternative is to keep plot BEFORE the if block but forr it to be returned by procedure work by writting 
return plot(...)


Download answer2.mw

 

You have a lot of mistakes in your code, essentially:

  • a wrong use of the option parameters in dsolve
    (look in my worksheet how to this correctly, see also the help page)
  • a wrong description of the arguments of SSQ
    (my worksheet + help page)
     

More of this the meaning of your command ip := subs(N, i(t)): is unclear: what it is that you want to do exactly?

To show you how SSQ would have been written, I ARBITRARILY replaced ip within it by B.
The line above SSQ is here to verify it works correctly.

See how the plot3d is written: you must protect SSQ(A,B) by enclosing it between quotes to prevent earlier evaluation.

I didn't go further because I do not understant what is the fit you want to do?

PS: all the corrections are yellow highligthed

 

restart;
with(plots): with(DEtools): with(LinearAlgebra): with(Statistics): with(CurveFitting): with(Optimization):

iV := Vector([300870, 83142, 155094, 146394, 177041, 94876, 150116, 158735, 228170, 144377, 167341, 44166, 136422, 125252, 161935, 138512], datatype = float);

iV := Vector(4, {(1) = ` 1 .. 16 `*Vector[column], (2) = `Data Type: `*float[8], (3) = `Storage: `*rectangular, (4) = `Order: `*Fortran_order})

(1)

len := Dimension(iV)

16

(2)

tV := Vector([seq(j, j = 1 .. len)])

tV := Vector(4, {(1) = ` 1 .. 16 `*Vector[column], (2) = `Data Type: `*anything, (3) = `Storage: `*rectangular, (4) = `Order: `*Fortran_order})

(3)

pp := plot(tV, iV, style = point):

eq1 := diff(B(T), T) = M__h-beta__1*psi*(B(T)+C(T))*H(T)-sigma*psi*beta__1*E(T)*DD(T)-mu__r*B(T)

diff(B(T), T) = M__h-beta__1*psi*(B(T)+C(T))*H(T)-sigma*psi*beta__1*E(T)*DD(T)-mu__r*B(T)

(4)

eq2 := diff(C(T), T) = beta__1*psi*(B(T)+C(T))*H(T)-(alpha+xi+mu__r)*C(T)

diff(C(T), T) = beta__1*psi*(B(T)+C(T))*H(T)-(alpha+xi+mu__r)*C(T)

(5)

eq3 := diff(DD(T), T) = alpha*C(T)-(varpi+xi+mu__r)*DD(T)

diff(DD(T), T) = alpha*C(T)-(varpi+xi+mu__r)*DD(T)

(6)

eq4 := diff(E(T), T) = varpi*DD(T)-(Ggamma+mu__r)*E(T)

diff(E(T), T) = varpi*DD(T)-(Ggamma+mu__r)*E(T)

(7)

eq5 := diff(F(T), T) = Ggamma*E(T)+sigma*psi*beta__1*F(T)*H(T)-mu__r*F(T)

diff(F(T), T) = Ggamma*E(T)+sigma*psi*beta__1*F(T)*H(T)-mu__r*F(T)

(8)

eq6 := diff(G(T), T) = M__c-psi*beta__o*G(T)*DD(T)-mu__b*G(T)

diff(G(T), T) = M__c-psi*beta__o*G(T)*DD(T)-mu__b*G(T)

(9)

eq7 := diff(H(T), T) = psi*beta__o*G(T)*DD(T)-mu__b*H(T)

diff(H(T), T) = psi*beta__o*G(T)*DD(T)-mu__b*H(T)

(10)

B0 := .50:
C0 := .30:
DD0 := 0.21:
E0 := 0.14:
F0 := 0.7:
G0 := 0.45:
H0 := 0.14:

sys := {eq1, eq2, eq3, eq4, eq5, eq6, eq7, B(0) = B0, C(0) = C0, DD(0) = DD0, E(0) = E0, F(0) = F0, G(0) = G0, H(0) = H0}

{B(0) = .50, C(0) = .30, DD(0) = .21, E(0) = .14, F(0) = .7, G(0) = .45, H(0) = .14, diff(B(T), T) = M__h-beta__1*psi*(B(T)+C(T))*H(T)-sigma*psi*beta__1*E(T)*DD(T)-mu__r*B(T), diff(C(T), T) = beta__1*psi*(B(T)+C(T))*H(T)-(alpha+xi+mu__r)*C(T), diff(DD(T), T) = alpha*C(T)-(varpi+xi+mu__r)*DD(T), diff(E(T), T) = varpi*DD(T)-(Ggamma+mu__r)*E(T), diff(F(T), T) = Ggamma*E(T)+sigma*psi*beta__1*F(T)*H(T)-mu__r*F(T), diff(G(T), T) = M__c-psi*beta__o*G(T)*DD(T)-mu__b*G(T), diff(H(T), T) = psi*beta__o*G(T)*DD(T)-mu__b*H(T)}

(11)

FreeParams := convert(indets(sys, name) minus {T}, list)

[Ggamma, M__c, M__h, alpha, beta__1, beta__o, mu__b, mu__r, psi, sigma, varpi, xi]

(12)

N := dsolve(
             sys,
             numeric,
             parameters = FreeParams,
             output = listprocedure
           );