Carolyn Davis

15 Reputation

3 Badges

2 years, 109 days

MaplePrimes Activity


These are questions asked by

Can anyone please assist with these errors?

#Clear memory.
restart;

#Initialise variables and arrays.
h:=Pi/10;
n:=10;
k:=0.1;  
m:=6;
t:=Array(0..m):
x:=Array(0..n):
u:=Array(0..n,0..m):

#Initialise the x array and the initial u(x,0) boundary.
for i from 0 to n do
    x[i]:=i*h;
    u[i,0]:=0;
end do:

#Initialise the t array and the u(x,t) side boundaries.
for j from 0 to m do
   t[j]:=j*k;
   u[0,j]:=0;
   u[n,j]:=3*sin*t[j];
end do:

#Use the 2D CTCS explicit wave method.
for i from 1 to n-1 do
   u[i,1]:=(u[i-1,0]/2*Pi^2+sin(x)/10*Pi^2+u[i+1,0]/2*Pi^2)-1;
end do:
 
for j from 1 to m-1 do
  for i from 1 to n-1 do
   u[i,j+1]:=(((u[i-1,j]+u[i+1,j]-u[i,j-1])/Pi^2)-2);
  end do;
end do:

#Display the u(x,t)values.
printf("2D CTCS Explicit Wave Method\n");
printf("----------------------------\n");
printf("x\t\t t\t\t u\n");
for i from 0 to n do
   printf("% f\t% f\t% f\n",x[i],t[m],u[i,m]);
end do;

(1/10)*Pi

 

10

 

.1

 

6

 

Error, invalid input: sin expects its 1st argument, x, to be of type algebraic, but received Array(0..10, [0,1/10*Pi,1/5*Pi,3/10*Pi,2/5*Pi,1/2*Pi,3/5*Pi,7/10*Pi,4/5*Pi,9/10*Pi,Pi])

 

2D CTCS Explicit Wave Method
----------------------------
x                 t                 u
 0.000000         0.600000         0.000000
 0.314159         0.600000        -2.015556
 0.628319         0.600000        -2.198509
 0.942478         0.600000        -2.215724
 1.256637         0.600000        -2.218015
 1.570796         0.600000        

 

Error, (in fprintf) number expected for floating point format

 

NULL


Download Asst_4_Question_2c.mw

For the t output I need to show 1, 1.2, 1.4....2, my attempt is highlighted in green below

Can anyone assist please?

#Clear memory and load packages.
restart;
with(plots):
with(Statistics):

#Define vectors and variables.
actual:=<2,3.5136,5.8016,9.1136,13.7376,20>:
t:=<1,1.2,1.4,1.6,1.8,2>:
n:=6:
RMSE:=0:

#Perform a simple linear regression on the data.
P:=LinearFit([1,x],t,actual,x);

#Display the model errors.
printf("t    Actual P  Model P  Error\n");
for i from 1 to n do
   model:=subs(x=t[i],P):
   err:=actual[i]-model:
   RMSE:=RMSE+err^2:
   printf("%2d %7.4f% 10.4f% 9.4f\n",(i+(1/5)),actual[i],model,err);
end do:

#Display the root mean square error.
RMSE:=sqrt(RMSE/n);

#Plot the points and the model.
p1:=plot(t,actual,style=point,view=[0..7,8..26]):
p2:=plot(P,view=[0..7,8..26]):
display(p1,p2);

-HFloat(17.540266666666668)+HFloat(17.712)*x

 

t    Actual P  Model P  Error

 

Error, (in fprintf) integer expected for integer format

 

HFloat(0.7463867411787324)

 

 

NULL

Download Asst_4_Question_1f.mw

Can anyone assist with this error please?

#Clear memory and load package.
restart;  
with(LinearAlgebra):

#Initialise variables,matrices and vectors.
b:=<<18>,<-2>>:
c:=<<1>,<1>>:
i:=0:
P:=<1.08,1.37,1.56,1.61>;
t:=<5,10,15,20>;
tol:=1e-6:

#Initialise Gauss-Newton matrices.
n:=Dimension(t):
f:=Matrix(n,1):
J:=Matrix(n,2):

#Display initial parameter values.
printf("Gauss-Newton Method\n");
printf("-------------------\n");
printf("Before iterations,A = %f and B = %f\n",b(1),b(2));

#Perform the Gauss-Newton method.
while max(abs(evalf(c)))>tol do
  i:=i+1;
  for r from 1 to n do
     f(r,1):=evalf((In(b(1)+t[r])+b(2))-P[r]);
     J(r,1):=evalf(1/b(1)+t[r]);
     J(r,2):=evalf(1);
end do;
c:=Multiply(MatrixInverse(Multiply(Transpose(J),J)),Multiply(Transpose(J),f));
b:=b-c;
printf("After iterations %d, A = %f and B = %f\n",i,b(1),b(2));
end do:

Vector(4, {(1) = 1.08, (2) = 1.37, (3) = 1.56, (4) = 1.61})

 

Vector[column](%id = 36893488152076174028)

 

Gauss-Newton Method
-------------------
Before iterations,A = 18.000000 and B = -2.000000
After iterations 1, A =

 

Error, (in fprintf) number expected for floating point format

 

NULL

Download Asst_3_Q4b.mw

The x region is z<x<1 and y region is 0<y<pi//3, I think there is an error in the j values in the loop

Can anyone assist please?

#Clear memory.
restart;

#Initialise variables and arrays.
h:=0.1;
k:=Pi/30;
c:=1:
iter:=0:
tol:=1e-5;
w:=1.5;
u:=Array(0..10,0..10):
U:=Array(0..10,0..10):

#Calculate boundary u values.
for i from 0 to 10 do

   u[i,Pi/3]:=0;
   u[i,0]:=0;
end do:

for j from 0 to Pi/3 do
   u[0,j]:=0;   
   u[10,j]:=sin(3*j*k)/2;
end do:
#Perform the Gauss-Seidel method.
while c>tol do
   iter:=iter+1;
   if iter>99 then
      printf("\nGauss-Seidel method did not converge,change w.\n");
   break;
end if:
for i from 1 to 9 do
  for j from 0 to Pi/3 do
     U[i,j]:=u[i,j];
     u[i,j]:=(10*Pi^2*u[i-1,j]+9*u[i,j-1]+9*u[i,j+1]+2*Pi^2*u[i+1,j])/20;
     u[i,j]:=w*u[i,j]+(1-w)*U[i,j];
  end do:
end do:
c:=max(abs(u[1..9,1..9]-U[1..9,1..9]));
printf("After iteration %2d,the maximum change in u is %7.1e\n",iter,c);
end do:

#Display the final u values if method converged.
if iter<100 then
    printf("\nGauss-Seidel Method\n");
    printf("-------------------\n");
    for j from 10 by -1 to 0 do
      for i from 0 to 10 do
        printf("%6.4f",u[i,j]);
    end do:
    printf("\n");
end do:
end if:

.1

 

(1/30)*Pi

 

0.1e-4

 

1.5

 

Error, bad index into Array

 

Error, final value in for loop must be numeric or character

 

Error, final value in for loop must be numeric or character

 


Gauss-Seidel Method
-------------------
0.00000.00000.00000.00000.00000.00000.00000.00000.00000.00000.0000
0.00000.00000.00000.00000.00000.00000.00000.00000.00000.00000.0000
0.00000.00000.00000.00000.00000.00000.00000.00000.00000.00000.0000
0.00000.00000.00000.00000.00000.00000.00000.00000.00000.00000.0000
0.00000.00000.00000.00000.00000.00000.00000.00000.00000.00000.0000
0.00000.00000.00000.00000.00000.00000.00000.00000.00000.00000.0000
0.00000.00000.00000.00000.00000.00000.00000.00000.00000.00000.0000
0.00000.00000.00000.00000.00000.00000.00000.00000.00000.00000.0000
0.00000.00000.00000.00000.00000.00000.00000.00000.00000.00000.0000
0.00000.00000.00000.00000.00000.00000.00000.00000.00000.00000.0000
0.00000.00000.00000.00000.00000.00000.00000.00000.00000.00000.0000

 

NULL

Download Asst_3_Q3c.mw

Can anyone assist with the error please?
 

#Clear memory.
restart;

#Initialise variables and arrays.
h:=0.1;
n:=10;
k:=0.1;  
m:=10;
t:=Array(0..m):
x:=Array(0..n):
u:=Array(0..n,0..m):

#Initialise the x array and the initial u(x,0) boundary.
for i from 0 to n do
    x[i]:=i*h;
    u[i,0]:=exp(x[i]);
end do:

#Initialise the t array and the u(x,t) side boundaries.
for j from 0 to m do
   t[j]:=j*k;
   u[0,j]:=0;
   u[n,j]:=t[j];
end do:

#Use the 2D CTCS explicit wave method.
for i from 1 to n-1 do
   u[i,1]:=(9*u[i-1,0]+14*u[i,0]+9*u[i+1,0])/32+[i]/10;
end do:
 
for j from 1 to m-1 do
  for i from 0 to n-1 do
   u[i,j+1]:=(9*u[i-1,j]+14**u[i,j]+9*u[i+1,j])/16-u[i,j-1];
  end do;
end do:

#Display the u(x,t)values.
printf("2D CTCS Explicit Wave Method\n");
printf("----------------------------\n");
printf("x\t\t t\t\t u\n");
for i from 0 to n do
   printf("% f\t% f\t% f\n",x[i],t[m],u[i,m]);
end do;

.1

 

10

 

.1

 

10

 

Error, Array index out of range

 

2D CTCS Explicit Wave Method
----------------------------
x                 t                 u
 0.000000         1.000000         0.000000
 0.100000         1.000000         0.000000
 0.200000         1.000000         0.000000
 0.300000         1.000000         0.000000
 0.400000         1.000000         0.000000
 0.500000         1.000000         0.000000
 0.600000         1.000000         0.000000
 0.700000         1.000000         0.000000
 0.800000         1.000000         0.000000
 0.900000         1.000000         0.000000
 1.000000         1.000000         1.000000

 

NULL


 

Download Asst_3_Q2b.mw

1 2 Page 1 of 2