nm

11353 Reputation

20 Badges

13 years, 10 days

MaplePrimes Activity


These are answers submitted by nm

You mean code block?  You can do the following

This will open a window

 

 

Now type the code inside it, then click OK

 

That is all.  To edit the code again, repeate the above process.

Here is one way (need Maple 2020 for the Slice command)

A:=Matrix(3, 5, [[2, -6, 3, 0, 0], [5, -2, 4, 1, 2], [17, -4, 10, 20, 99]]);
ListTools:-Slice(convert(A^+,list),LinearAlgebra:-RowDimension(A))

Here is another way

convert~([seq(A[i],i=1..LinearAlgebra:-RowDimension(A))],list);

split_expr:=proc(expr::anything)
 if type(expr,`+`) then
    return convert(expr,list);
 elif type(expr,`list`) then
    return expr;
 else
    return [expr];
 fi;
end proc;

create file data.csv  (ps. you have 6 variables actually not 5, but you can change this)

2,-6,3,0,0
5,-2,4,1,2
17,-4,10,20,99

Then write

restart;
currentdir("C:/tmp"); #where the data.csv file is
data := Import("data.csv"):
data := convert(data,Matrix):
nRows,nCols := LinearAlgebra:-Dimension(data);
for n from 1 to nRows do
    unassign('a,h,b,f,g'):
    assign~([a,h,b,f,g],convert(data[n],list)):
    Conic:=a*x^2+2*h*x*y+b*y^2+2*f*x+2*g*y+c;
od;

 

I can't belive it! No Fourier Series in Maple!!! What a shame!

sorry, I didn't realize OP wanted solution using only Maple build-in commands and not using external package OrthogonalExpansions. Will try to find if I can find build-in Maple command to do this if possible.

 

default Digits is 10. As a rule, delay using machine numbers to the very end. So instead of 

Iabcx := subs[eval]({a=1.0} , Iabc); replace with Iabcx := subs[eval]({a=1} , Iabc);

 

And at the very end, instead of doing

simplify(evalf(Ipnz))

 

You can do

Digits:=16;
simplify(evalf(Ipnz))

or

simplify(evalf[16](Ipnz))

both will give

But why do you want to do this in first place? Why not keep it symbolic:

simplify(Ipnz)

It looks better and more accurate since exact.


 

Looking at your code

rmse_mlr:=proc(Full)
local i, sq, n, predicted;

sq:=0:
for i from 1 to n do
     predicted:=subs([a=X[i,1],b=X[i,2],c=X[i,3],d=X[i,4]],Full);
     sq:=sq+(Y[i]-predicted)^2;
end do:

return sqrt(sq/n);

end proc;

The call is rmse_mlr(FullEQN,X,Y);

The first thing to notice, is that you are calling it with 3 arguments, but it accepts only the first.

The second is that your loop is from 1 to n but there is no value given for anywhere.

I suggest your run lint on your code, and also use the debugger.  To use the debugger, so stopat(function_name);  and now when you invoke the function, the debugger will start. This way you can see what other problems you might have.

I also noticed you are doing convert(M,matrix) But are using LinearAlgebra. May be you should use Matrix. same for vector, change it to Vector

 

 

it is having hard time with the BC and ic. But it does odetest the pde itself once you remove the casesplit. It does not seem to handle casesplit well.

restart;
eq := diff(u(x, t), t) - k*diff(u(x, t), x, x) = 0;
ic := u(x, 0) = g(x);
bc  := D[1](u)(0,t)=0,(D[1](u)(1,t)+u(1,t))=0;
sol := (simplify(pdsolve([eq, ic, bc])) assuming (0 < k, 0 < x and x < 1, 0 < t));

Just remove the last where stuff (for the eigenvalues conditions it found)

sol:=u(x,t) = Sum(4*exp(-k*lambda[n]^2*t)*lambda[n]*cos(lambda[n]*x)
*Int(g(x)*cos(lambda[n]*x),x = 0 .. 1)/(2*lambda[n]+sin(2*lambda[n])),n = 0 ..
infinity)

And now it works just for the pde itself.

pdetest(sol, eq)

     0

And for the BC, it gives  zero for the left side one. But not for the right side one

pdetest(sol,[eq,bc])

if I understand you right, one way could be to convert it to list, then use plot


A:= seq(f(i), i = 0 .. 1, 0.1);
A:=convert~([A],list);

  #A := [[0, 1], [0.1, 1.1], [0.2, 1.2], [0.3, 1.3], [0.4, 1.4], [0.5, 1.5], [0.6, 1.6], [0.7, 1.7], [0.8, 1.8], [0.9, 1.9], [1.0, 2.0]]

plot(A[1..nops(A),1],A[1..nops(A),2], style=point)

one way

restart;
A:=Matrix([[1,2,3],[4,5,6],[7,8,9]]):
add((x->x^2)~(ArrayTools:-Diagonal(A)))

 

    107

 

CAS gives generic solution for the Euler ODE. Same solution is given by Mathematica.

To get specific solutions use assumptions

restart;
ode:=x^2*diff(y(x), x, x) + 3*x*diff(y(x), x) + lambda*y(x) = 0:
dsolve(ode) assuming lambda>1;
dsolve(subs(lambda=1,ode));
dsolve(ode) assuming lambda<1;

 

Noticed that assuming lambda=1 does not work.

 

another option 

 

restart;
r:=theta->cos(2*theta); 
plots:-animate(plots:-polarplot, [r(theta) , theta=0..max_angle], max_angle=0..2*Pi,frames=100)

 

it is type=numeric  and not type=numerical 

You also have singularity. (btw, strange name you picked for your dependent variable function, n? Also need to use midpoint method for the BVP

restart;

A1 := 8*Pi^3*R^2*n(x)^4*m+(2*Pi*sin((1/2)*x)*m*omega0*p+Pi*sin((1/2)*x)*m*omega0+3*Pi^2*(diff(n(x), x, x)))*n(x)^3+(-2*sin((1/2)*x)^2*m^2*omega0^2*p^2+2*cos((1/2)*x)^2*m^2*omega0^2*p^2-2*sin((1/2)*x)^2*m^2*omega0^2*p+2*cos((1/2)*x)^2*m^2*omega0^2*p)*n(x)^2+(-4*(diff(n(x), x$2))*sin((1/2)*x)^2*m^2*omega0^2*p^2-8*sin((1/2)*x)*(diff(n(x), x))*cos((1/2)*x)*m^2*omega0^2*p^2-4*(diff(n(x), x$2))*sin((1/2)*x)^2*m^2*omega0^2*p-8*sin((1/2)*x)*(diff(n(x), x))*cos((1/2)*x)*m^2*omega0^2*p)*n(x)+8*sin((1/2)*x)^2*(diff(n(x), x))^2*m^2*omega0^2*p^2+8*sin((1/2)*x)^2*(diff(n(x), x))^2*m^2*omega0^2*p;

R := 1; m := 1; p := 10; omega0 := 1000;

bc:=n(0) = n(4*Pi), (D(n))(0) = (D(n))(4*Pi);
sol:=dsolve([A1,bc], type = numeric, range = 0 .. 4*Pi,method=bvp[middefer]):

 

Error, (in dsolve/numeric/bvp) singularity encountered

Maple does not seem to like your BC. Something to look into.
 

 

 

There is something very confusing here. You say "need to find involved integration constant i.e c1 to c4. "  But you are providing boundary condition? There will not be any constants of integration in the solution., 

Also, why do you call "c1" a constant of integration, when it is part of the ODE itself? You wrote 

ode1:=diff(q(y), y$2) - A*q(y) = B*(P*y + c1);

And then you called c1 constant of integration?

In addition, your ODE's are not coupled. The first ODE can be solved on its own, and the solution plugged into the second ODE to solve that on its own. Coupled ODE's is when both dependent variable appear in both ODE's.

But you can still solve these ODE together, it does not matter to Maple

restart;
ode1:=diff(q(y), y$2) - A*q(y) = B*(P*y + c1);
bc1 := q(-sigma) = 0, q(sigma) = 0;
ode2:=(1 + N)*diff(u(y), y$2) + N*diff(q(y), y) = P;
bc2 := u(-sigma) = 1, u(sigma) = -k;
dsolve([ode1,ode2,bc1,bc2])

And since the ODE's are not coupled they can be solved one at a time:


restart
ode1:=diff(q(y), y$2) - A*q(y) = B*(P*y + c1);
bc1 := q(-sigma) = 0, q(sigma) = 0;
ode2:=(1 + N)*diff(u(y), y$2) + N*diff(q(y), y) = P;
bc2 := u(-sigma) = 1, u(sigma) = -k;
solq:=dsolve([ode1,bc1]);

ode2:=subs(solq,ode2);
solu:=dsolve([ode2,bc2])

Which gives same solutions are above

I normally use subs and algsubs.

subs seems to have worked here

subs(5435 + 3*sqrt(515793)=t,s1)

and simplify on the above gives

First 12 13 14 15 16 17 18 Page 14 of 20