## 125 Reputation

5 years, 267 days

## Error table between exact and numeric so...

Maple 2020

I have a table that includes the numeric and exact solution of a complex PDE.

I want to calculate error between exact and numeric solution.
Question 1: Which type of error is mostly used for complex solutions? Absolute error or relative error ,ecludian norm error etc.

Question 2: How to calculate absolute error in complex solutions?

|abs(Exact_Solution)-abs(Numeric_Solution)|

or

|abs(Exact_Solution-Numeric_Solution)|

restart:
interface(rtablesize=19):
Table_1:=Matrix(19,4,{(1, 1) = x, (1, 2) = t, (1, 3) = Exact_Solution, (1, 4) =
Numeric_Solution, (2, 3) = .58480350959087385609+1.0129093910559867400*I, (2, 4
) = .58480354764257321311+1.0129094569634633407*I, (3, 2) = .2, (3, 3) = .58507\
763625784549559+1.0133841923708911330*I, (3, 4) = .58507767430954485264+1.01338\
42582783677337*I, (4, 2) = .4, (4, 3) = .58590001649935378049+1.014808596732324\
2462*I, (4, 4) = .58590005455105313755+1.0148086626398008469*I, (5, 2) = .6, (5
, 3) = .58727066619506620449+1.0171826316446769860*I, (5, 4) = .587270690527719\
69197+1.0171826737900691093*I, (6, 2) = .8, (6, 3) = .58918956627727806829+1.02\
05062640817160297*I, (6, 4) = .58918959060993155574+1.0205063062271081530*I, (7
, 2) = 1.0, (7, 3) = .59165666981620797589+1.0247794127586756112*I, (7, 4) = .5\
9165677643905044333+1.0247795974348560123*I, (8, 1) = .5, (8, 3) = .59165805893\
555155139+1.0247818187839564608*I, (8, 4) = .59165677643905044333+1.02477959743\
48560123*I, (9, 1) = .5, (9, 2) = .2, (9, 3) = .58919046685310110177+1.02050782\
39247975919*I, (9, 4) = .58918959060993155574+1.0205063062271081530*I, (10, 1)
= .5, (10, 2) = .4, (10, 3) = .58727131671750391922+1.0171837583825905714*I, (
10, 4) = .58727069052771969197+1.0171826737900691093*I, (11, 1) = .5, (11, 2) =
.6, (11, 3) = .58590207620818846348+1.0148121642526747156*I, (11, 4) = .5859000\
5455105313755+1.0148086626398008469*I, (12, 1) = .5, (12, 2) = .8, (12, 3) = .5\
8507958971290229630+1.0133875758542998141*I, (12, 4) = .58507767430954485264+1.\
0133842582783677337*I, (13, 1) = .5, (13, 2) = 1.0, (13, 3) = .5848057178847424\
9287+1.0129132159331652617*I, (13, 4) = .58480354764257321311+1.012909456963463\
3407*I, (14, 1) = 1.0, (14, 3) = .61222010009837745680+1.0603963187852935669*I,
(14, 4) = .61222010009837745677+1.0603963187852935669*I, (15, 1) = 1.0, (15, 2)
= .2, (15, 3) = .60700988526763399480+1.0513719619800970123*I, (15, 4) = .60700\
988526763399480+1.0513719619800970123*I, (16, 1) = 1.0, (16, 2) = .4, (16, 3) =
.60234868471511732616+1.0432985257988700194*I, (16, 4) = .60234868471511732617+
1.0432985257988700194*I, (17, 1) = 1.0, (17, 2) = .6, (17, 3) = .59823621894610\
415849+1.0361755261425513984*I, (17, 4) = .59823621894610415846+1.0361755261425\
513983*I, (18, 1) = 1.0, (18, 2) = .8, (18, 3) = .59467229263079952050+1.030002\
6246900120270*I, (18, 4) = .59467229263079952054+1.0300026246900120270*I, (19,
1) = 1.0, (19, 2) = 1.0, (19, 3) = .59165677643905044330+1.0247795974348560123*
I, (19, 4) = .59165677643905044333+1.0247795974348560123*I},datatype = anything
,storage = rectangular,order = Fortran_order,shape = [])

## Verifying whether two formulas are equal...

Maple

Is the following function w

equal to next functions for a=1 or a= -1?

if a=1 then

w=

if a=-1 then

w=

where n>1, B,c and k are arbitrary constants.

################################
restart:
a:=-1:
B:=0:
c:=2:
h:=1:

#assume(n>1):
n:=3:
assume(0<=x and x<h):
assume(0<=t and t<h):

a:=-1:
if is(a>0)=true then
omega:=(x,t)->((2*c*n/(a*(n+1)))*(sin ((x-c*t+B)*sqrt(a)*(n-1)/(2*n)))^2 )^(1/(n-1));
print(omega(x,t));
elif is(a<0)=true then
omega:=(x,t)->(-(2*c*n/(a*(n+1)))*sinh ((x-c*t+B)*sqrt(-a)*(n-1)/(2*n))^2 )^(1/(n-1));
print(omega(x,t));
end if:

plot3d(omega(x,t),x=0..1,t=0..1);
################################

################################
restart:
a:=-1:
n:=3:
c:=2:
r:=0:
k_1:=0:
k_2:=0:
h:=1:

n:=3:
assume(0<=x and x<h):
assume(0<=t and t<h):
if a=1 then
omega:=(x,t)->piecewise(abs(x-c*t)<=2*n*(k_1-r)*Pi/(k_1*(n-1)),(sqrt(2*c*n/(n+1))*sin ((x-c*t)*(n-1)/(2*n)+r*Pi/k_1))^(2/(n-1)),0);
print(omega(x,t));
elif a=-1 then
omega:=(x,t)->(sqrt(2*c*n/(n+1))*sinh ((x-c*t)*(n-1)/(2*n)+k_2))^(2/(n-1));
print(omega(x,t));
end if:

plot3d(omega(x,t),x=0..1,t=0..1);

## Unwanted quotation marks in the matrix (...

Maple

I imported the Excel file test.xlsx to Maple with ExcelTools, but I got unwanted quotation marks in Matrix B.

Question 1: What is the reason?

Question 2: How to remove the quotes?

restart:
with(ExcelTools);
interface(rtablesize=20):
B:=ExcelTools:-Import("C:\\Users\\Maplelover\\Desktop\\test.xlsx", "Table 1");


## For the Latex code for a Matrix...

Maple

For the Latex code of matrix B, I used the following procedure. But the last column of B is not what we're looking for in the latex code. (There is no problem in the other columns)

restart:
interface(rtablesize=20):
f:=(x,t)->x*t;
g:=(x,t)->x^2*t;

B:=Matrix([[x,t,"f(x,t)","g(x,t)"],
seq(seq([i,j,f(i,j),g(i,j)],
j=0.125..0.875, 0.25),
i=0.125..0.875,0.25)]):
B[1,..]:=map(p->nprintf(#mi(%a);,p),B[1,..]):
B[2..,4]:=map(p->nprintf(#mn(\"%1.2e\");,p),B[2..,4]):

Lat:=proc(M::Matrix,
{output::{NoUserValue,identical(string)}:=':-NoUserValue'})
local m,n,S;
(m,n):=op(1,M);
S:=cat(" \\begin{tabular}",
"{|",seq("c|",i=1..op([1,2],M)),"} ",
"\\hline ",
seq([seq(sprintf("$%s$ & ",latex(M[i,j],':-output'=string)),j=1..n-1),
sprintf("$%s$ \\\\ \\hline ",latex(M[i,n],':-output'=string))][],i=1..m),
"\\end{tabular} ");
if output=':-string' then
return S;
else
printf("%s",S);
return NULL;
end if;
end proc:
Lat(B);


## Another question: scientific notation...

Maple

Another question:

I want to write the values of function g(x,t) as scientific notation.  I mean I want to write 1.95*10^(-3)  instead of 0.001953125 etc.

Yes, by clicking right-click and clicking the numeric formatting, I can transform all columns of Array A, but I want to transform just the last column g(x,t) in Array A.

restart:
f:=(x,t)->x*t;
g:=(x,t)->x^2*t;interface(rtablesize=20):
A:=Array( [ [x,t,f(x,t), g(x,t)],
seq
( seq
( [i, j, f(i,j), g(i,j)],
j=0.125..0.875, 0.25
),
i=0.125..0.875, 0.25
)
]
);


 1 2 3 Page 1 of 3
﻿