Spirithaunter

75 Reputation

One Badge

2 years, 214 days

MaplePrimes Activity


These are questions asked by Spirithaunter

Hi dear community!

 

The following code produces a table, however it always has the text "Tabulate0" as an output as well. Is it possible to supress that? Ordinary : dont work unfortunately.

 

with(DocumentTools):
with(ArrayTools):
nUnten:=2:
nOben:=8:
InitialisierungDF:=Vector[column](nOben-nUnten+1, fill=oE): #Erstellen der auszugebenden Tabelle
InitialisierungSpalte:=Vector[row](nOben-nUnten+1, i->n=nUnten-1+i):
DF:= DataFrame( Concatenate( 2, InitialisierungDF $ 10),
                   columns = [ GKAbs, GKRel, PZPAbs, PZPRel, PZMAbs, PZMRel, PYAbs, PYRel, DAbs, DRel],
                   rows = InitialisierungSpalte);
print(Tabulate(DF));

 

Thank you very much!

Hi there!

The first time I compile the following code, I get the error message

"Error, cannot split rhs into multiple assignment."

when trying to solve an issue with the procedure. I then have to compile the procedure over and over again, until it finally works (which it does eventually, without changing the code.) The problematic line is

Knoten, Eigenvektoren := Eigenvectors(evalf[15](M));

it is one of the last lines within the code below. Is it possible to get rid of that issue? It is annoying and unprofessional to have to compile a code over and over again until it finally works.

 

 

 

GaußKronrodQuadraturKurz:= proc(Unten, Oben, f,G,n)::real;
 
  #Unten:= Untere Intervallgrenze; Oben:= Obere Intervallgrenze; G:= Gewicht;
  #f:= zu untersuchende Funktion; n:= Berechnung der Knotenanzahl mittels 2*n+1
local
A,B,P,S,T, #Listen
a,b,p,s,t, #Listenelemente
i,j,k, #Laufvariablen
M, #werdende Gauss-Kronrod-Jacobi-Matrix
m, #Matrixeinträge
u,l, #Hilfsvariablen Gemischte Momente
RekursivesZwischenergebnis,Gewichte,Knoten,Eigenvektoren,AktuellerNormierterVektor,Hilfsvariable,Endergebnis;

with(LinearAlgebra):
 
A := [seq(a[i], i = 0 .. n)];
B := [seq(b[i], i = 0 .. n)];
P := [seq(p[i], i = -1 .. ceil(3*n/2)+1)];  
S := [seq(s[i], i = -1 .. floor(n/2))];
T := [seq(t[i], i = -1 .. floor(n/2))];
p[-1]:= 0;
p[0]:=1;
for i from -1 to floor(n/2) do
  s[i]:=0;
  t[i]:=0
end do;
for j from 1 to 2*n+1 do
  RekursivesZwischenergebnis:= x^j;
  for i from 0 to j-1 do
    RekursivesZwischenergebnis:= RekursivesZwischenergebnis -
    (int(x^j*p[i],x=Unten..Oben)/int(p[i]*p[i],x=Unten..Oben))*p[i]                  #Gram-Schmidt algorithm
  end do;
  p[j]:=RekursivesZwischenergebnis;
end do;
a[0]:=-coeff(p[1],x,0);

  #p[0+1]=(x-a[0])*p[0]-b[0]*p[0-1] -> p[1]=x*p[0]-a[0]*p[0]-b[0]*p[-1] ->
  #p[1]=x*1-a[0]*1-0 -> a[0]=x-p[1] -> a[0]= -coeff(p[1],x,0), da p[1] monisch ist und von Grad 1    #ist
 
b[0]:=int(p[0]^2, x=Unten..Oben); #by definition
for j from 1 to ceil(3*n/2) do
 
  #Genau genommen muss a nur bis floor(3/(2*n)) initialisiert werden, allerdings wird der Wert       #ohnehin für die Berechnung von b gebraucht. Die Initialisierung schadet nicht.
    
                                     
  a[j]:= coeff(p[j],x,j-1)- coeff(p[j+1],x,j);
    
    #p[j+1]=(x-a[j])*p[j]-b[j]*p[j-1] -> p[j+1]=x*p[j]-a[j]*p[j]-b[j]p[j-1] ->
    #coeff(p[j+1],x,j)=coeff(x*p[j],x,j)-coeff(a[j]*p[j],x,j)
      #(da b[j]*p[j-1] vom Grad j-1 ist) ->
    #coeff(p[j+1],x,j)=coeff(x*p[j],x,j)-a[j], da p[j] monisch ist ->
    #coeff(p[j+1],x,j)=coeff(p[j],x,j-1)-a[j]->
    #a[j]=coeff(p[j],x,j-1)-coeff(p[j+1],x,j)
 
  b[j]:=  quo((x-a[j])*p[j]-p[j+1],p[j-1],x);
    

     #p[j+1]=(x-a[j])*p[j]-b[j]*p[j-1] -> -p[j+1]+(x-a[j])*p[j]= b[j]*p[j-1]
     #b[j]=((x-a[j])*p[j]-p[j+1])/p[j-1]

end do;    
t[0]:=b[n+1]; #t[0]:= /hat{b}[0], Beginn der ostwärtigen Phase
for i from 0 to n-2 do # n-2 ist die Anzahl der zu berechnenden Diagonalen
  u:=0;
  for k from floor((i+1)/2) to 0 by -1 do # aufgrund des diagonalen Vorgehens ist nur bei jedem
                                          # zweiten Schleifendurchlauf eine Inkrementierung
                                          # vorzunehmen
    l:=i-k;
    u:=u+(a[k+n+1]-a[l])*t[k]+b[k+n+1]*s[k-1]-b[l]*s[k]; # Ausrechnen gemischter Momente über die
                                                         # fünfgliedrige Rekursion
    s[k]:=u
  end do;
  for j from -1 to floor(n/2) do  # Durchrotieren der Werte der gemischten Momente, da ein                                           # jeweiliges gemischtes Moment beim zweiten auf die Generierung                                    # folgenden
                                  # Schleifendurchlauf das letzte mal benötigt und danach über-
                                  # schrieben wird. Die am Ende vorliegenden Werte sind gerade
                                  # die, die bei der südwärtigen Phase benötigt werden.
    Hilfsvariable:=s[j];
    s[j]:=t[j];
    t[j]:=Hilfsvariable
  end do;
end do;
for j from floor(n/2) to 0 by -1 do
    s[j]:=s[j-1]
end do;
for i from n-1 to 2*n-3 do #entspricht der Anzahl der restlichen Diagonalen
  u:=0;
  for k from i+1-n to floor((i-1)/2) do #berechnet die gemischten Momente innerhalb einer
                                        #Diagonalen, von oben rechts nach unten links.
    l:=i-k;
    j:=n-1-l;
    u:=u-(a[k+n+1]-a[l])*t[j]-b[k+n+1]*s[j]+b[l]*s[j+1];
    s[j]:=u
  end do;
  if i mod 2 = 0 then #Ausrechnen eines fehlenden Koeffizienzen über die fünfgliedrige Rekursion                         #am Eintrag (k,k)
    k:= i/2;
    a[k+n+1]:=a[k]+(s[j]-b[k+n+1]*s[j+1])/t[j+1]
  else                #Ausrechnen eines fehlenden Koeffizienzen über die fünfgliedrige Rekursion                         #am Eintrag (k,k-1)
    k:=(i+1)/2;
    b[k+n+1]:=s[j]/s[j+1]
  end if;
  for j from -1 to floor(n/2) do #Erneutes Durchrotieren der Werte der gemischten Momente
    Hilfsvariable:=s[j];
    s[j]:=t[j];
    t[j]:=Hilfsvariable
  end do;
end do;
a[2*n]:=a[n-1]-b[2*n]*s[0]/t[0]; #Berechnung des letzten fehlenden Koeffizienten über die                                           #fünfgliedrige Rekursion am Eintrag (n-1,n-1)

M:=Matrix(2*n+1, shape=symmetric);#definieren der werdenden Gauß-Krondrod-Matrix
M(1,1):=a[0];
for m from 2 to (2*n+1) do #generieren der Gauss-Kronrod-Matrix
  M(m-1,m):= sqrt(b[m-1]);
  M(m,m-1):= sqrt(b[m-1]);
  M(m,m):= a[m-1];
end do;
Knoten, Eigenvektoren := Eigenvectors(evalf[15](M));# "Die gesuchten Knoten sind die Eigenwerte #dieser Matrix, und die Gewichte sind proportional zu den ersten Komponenten der normalisierten #Eigenvektoren"

 

for m from 1 to 2*n+1 do
  AktuellerNormierterVektor:= Normalize(Column(Eigenvektoren,m),Euclidean);
 
 
  Gewichte[m]:=AktuellerNormierterVektor[1]^2*b[0]

end do;

Endergebnis:=Re(add(Gewichte[i]*eval(f*diff(G,x),x=Knoten[i]),i=1..2*n+1));

 

end proc

 

An example of an application of the procedure is

 

GaußKronrodQuadraturKurz(-2, 1, 3*x*3*x^2*sin(x),x,3)

 

Thank you very much!

 

Hi,

 

I am looking to convert two expressions into to one, however, their arguments are supposed to be numerically in order:

fsolve(2*x^5-x^4-0.5*x^3+3*x^2-0.5)
            -1., -0.415862444399209580898770761551,0.425609408597783496007437773936


fsolve(x^2-1)
              -1.00000000000000000000000000000, 1.

For my procedure, I need them in order, namely

-1,-1, -0.415862444399209580898770761551,0.425609408597783496007437773936,1

Is it possible to do this with expressions without having to convert them to a list? Since my following code expects expressions, and not lists, I wouldn't like to change the whole program around it.

Hi!

 

Is there a way to use the profiling function for procedures within a procedure? I have this code as an example:

Test:=proc(a,b)::real;

local c;Ergebnis;

Test2:= proc(d,e) #Prozedur zum Schreiben der Ausgaben

    f:=d+e;
    g:=f*d;
    5+3;
    3/0;
end proc:
 c:=a+b;
 Ergebnis:=Test2(a,c)
 end proc:

infolevel[Test]:= 2:
CodeTools:-Profiling:-Profile(Test):
Test(3,4);
CodeTools:-Profiling:-PrintProfiles(Test);

just profiling Test2, the subprocedure, doesn't do anything. Obviously, in this example, the division by zero is the problem, however, I am interested in a general solution to detect more complicated problems within a sub-procedure. Is there a way to also profile it, and thus see where the computation stops?

Hi!

 

I am trying to construct multiple math plots within one procedure, however, only one is displayed at a time, and it is always at the end of the outputs. I searched for that peculiar behaviour and eventually found on

https://de.maplesoft.com/support/help/Maple/view.aspx?path=DataFrame/Tabulate

the line

This command inserts the assembly of Tables and Embedded Components into the worksheet using the InsertContent facility. The inserted content is placed after any usual output of the Execution Group in which this command is called. Each Execution Group allows for only one inserted result to exist at any given time. Multiple calls to commands which utilize the InsertContent facility made within the same Execution Group will result in each successive inserted assembly replacing any assembly inserted earlier for that Execution Group.

 

Is there a workaround for this issue? I cannot find one, e.g. on

https://de.maplesoft.com/support/help/Maple/view.aspx?path=DocumentTools%2fInsertContent

Thank you in advance. :)

1 2 3 4 Page 1 of 4