Carolyn Davis

15 Reputation

3 Badges

2 years, 110 days

MaplePrimes Activity


These are questions asked by

I'm unsure how to fix the error with sin, the help guide suggests using the command Describe (Sin)

#Clear memory.
restart;

#Initialise variables and arrays.
h:=((pi/20)^2);
n:=15;
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]:=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]:=pi/2;
end do:

#Use the 2D explicit finite difference method.
for j from 0 to m-1 do
    for i from 1 to n-1 do
      u[i,j+1]:=(400*u[i-1,j]-400*u[i,j]+400*u[i+1,j]+1)/(pi^2)*(4*sin(2*x));
  end do;
end do:

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

(1/400)*pi^2

 

15

 

.1

 

10

 

Error, invalid input: sin expects its 1st argument, x, to be of type algebraic, but received Array(0..15, [0,1/200*pi^2,1/100*pi^2,3/200*pi^2,1/50*pi^2,1/40*pi^2,3/100*pi^2,7/200*pi^2,1/25*pi^2,9/200*pi^2,1/20*pi^2,11/200*pi^2,3/50*pi^2,13/200*pi^2,7/100*pi^2,3/40*pi^2])

 

2D Explicit Finite Difference Method
------------------------------------
 x                 t                 u
   0.0000           1.0000           0.0000

 

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

 

NULL

Download Asst_2_Q3bcd.mw

#Clear memory.
restart;

#Initialise variables and arrays.
h:=0.1;
n:=10;
x:=Array(0..n):
y:=Array(0..n):
x[0]:=0;
y[0]:=2;
yd:=-1;

#Initialise the x array.
for i from 1 to n do
    x[i]:=x[0]+i*h;
end do:

#Calculate the first y value.
y[1]:=(203*y[0]-22*yd+4)/220:

#Calculate the remaining y values.
for i from 1 to n-1 do
    y[i+1]:=203*y[i]-110*y[i-1]+4*exp^(-3*x[i])/110;
end do:

#Display the x and y arrays.
printf("1D Explicit Finite Difference Method\n");
printf("------------------------------------\n");
printf("x\t\ty\n");
for i from 0 to n do
     printf("%f\t %f\n",x[i],y[i]);
end do;

 

.1

 

10

 

0

 

2

 

-1

 

1D Explicit Finite Difference Method
------------------------------------
x                y
0.000000         2.000000
0.100000         1.963636
0.200000         

 

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

 

NULL

Download Asst_2_Q1c.mw

I dont understand the cause of this error, can anyone please assist?

1 2 Page 2 of 2