Kitonum

14453 Reputation

24 Badges

11 years, 269 days

MaplePrimes Activity


These are answers submitted by Kitonum

In fact, after calculating the derivatives, we get a linear system:

NULL

restart

Jestar := .222222222222222222222222222223*x[1]+3.98408963290776835548901841189+.222222222222222222222222222223*u[1]^2+1.20728063844142489971746563410*u[1]+.555555555555555555555555555557*x[2]+.555555555555555555555555555557*u[2]^2+2.19736562704190744843616437593*u[2]+.222222222222222222222222222218*x[3]+.222222222222222222222222222218*u[3]^2+.894156749261387141869195542552*u[3]+lambda[1]*(1.2*10^(-29)*x[1]-2.2*10^(-29)*x[2]+7.8*10^(-30)*x[3])+lambda[2]*(-1.61439242336161127378313801260*x[1]+.45420549105153639573117683365*x[2]+.16018693231007487805196117895*x[3]-1.*u[2])+lambda[3]*(-.95012749286786619995420043248*x[1]-.51534877135614818507764030330*x[2]+.46547626422401438503184073577*x[3]-1.*u[3])

.222222222222222222222222222223*x[1]+3.98408963290776835548901841189+.222222222222222222222222222223*u[1]^2+1.20728063844142489971746563410*u[1]+.555555555555555555555555555557*x[2]+.555555555555555555555555555557*u[2]^2+2.19736562704190744843616437593*u[2]+.222222222222222222222222222218*x[3]+.222222222222222222222222222218*u[3]^2+.894156749261387141869195542552*u[3]+lambda[1]*(0.1200000000e-28*x[1]-0.2200000000e-28*x[2]+0.7800000000e-29*x[3])+lambda[2]*(-1.61439242336161127378313801260*x[1]+.45420549105153639573117683365*x[2]+.16018693231007487805196117895*x[3]-1.*u[2])+lambda[3]*(-.95012749286786619995420043248*x[1]-.51534877135614818507764030330*x[2]+.46547626422401438503184073577*x[3]-1.*u[3])

(1)

Sys := {seq(diff(Jestar, lambda[i]) = 0, i = 1 .. 3), seq(diff(Jestar, u[i]) = 0, i = 1 .. 3), seq(diff(Jestar, x[i]) = 0, i = 1 .. 3)}

{.4444444444*u[1]+1.20728063844142489971746563410 = 0, 1.111111111*u[2]+2.19736562704190744843616437593-1.*lambda[2] = 0, .4444444444*u[3]+.894156749261387141869195542552-1.*lambda[3] = 0, 0.1200000000e-28*x[1]-0.2200000000e-28*x[2]+0.7800000000e-29*x[3] = 0, .222222222222222222222222222218+0.7800000000e-29*lambda[1]+.16018693231007487805196117895*lambda[2]+.46547626422401438503184073577*lambda[3] = 0, .222222222222222222222222222223+0.1200000000e-28*lambda[1]-1.61439242336161127378313801260*lambda[2]-.95012749286786619995420043248*lambda[3] = 0, .555555555555555555555555555557-0.2200000000e-28*lambda[1]+.45420549105153639573117683365*lambda[2]-.51534877135614818507764030330*lambda[3] = 0, -1.61439242336161127378313801260*x[1]+.45420549105153639573117683365*x[2]+.16018693231007487805196117895*x[3]-1.*u[2] = 0, -.95012749286786619995420043248*x[1]-.51534877135614818507764030330*x[2]+.46547626422401438503184073577*x[3]-1.*u[3] = 0}

(2)

solve(Sys)

{lambda[1] = -0.3405136588e31, lambda[2] = -73.32501333, lambda[3] = 81.81631382, u[1] = -2.716381437, u[2] = -67.97014107, u[3] = 182.0748534, x[1] = -8572.737031, x[2] = -17682.28255, x[3] = -36684.27842}

(3)

NULL

NULL


 

Download example-new.mw

y = x*(x^4 - 10*x^2 + 39)/30

For best results, I replaced the constant  2  with a third parameter  a3 . We specify the segment  [a,b]  and the step  h  to obtain data  X  and  Y  and then use the  Statistics:-NonlinearFit  command. When reducing the segment  [a,b] , we get better results:
 

restart;
a, b:=0, 5:
f1:=x->(2*x)/(3+5*x):  
f2:=x->a1*(a3-exp(-a2*x)):
h:=0.1: n:=(b-a)/h;
X:=[seq(i*h,i=0..n)];
Y:=[seq(f1(i*h),i=0..n)];
F:=Statistics:-NonlinearFit(f2(x), X, Y, x);
plot([f1(x),F], x=0..5, color=[blue,red],legend=["f1","f2"]);

50.00000000

 

[0., .1, .2, .3, .4, .5, .6, .7, .8, .9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3.0, 3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 4.0, 4.1, 4.2, 4.3, 4.4, 4.5, 4.6, 4.7, 4.8, 4.9, 5.0]

 

[0., 0.5714285714e-1, .1000000000, .1333333333, .1600000000, .1818181818, .2000000000, .2153846154, .2285714286, .2400000000, .2500000000, .2588235294, .2666666666, .2736842106, .2800000000, .2857142858, .2909090910, .2956521740, .3000000000, .3040000000, .3076923076, .3111111112, .3142857142, .3172413794, .3200000000, .3225806452, .3250000000, .3272727272, .3294117648, .3314285714, .3333333334, .3351351352, .3368421052, .3384615384, .3400000000, .3414634146, .3428571428, .3441860466, .3454545454, .3466666666, .3478260870, .3489361702, .3500000000, .3510204082, .3520000000, .3529411764, .3538461538, .3547169812, .3555555556, .3563636364, .3571428572]

 

HFloat(0.3473297773329595)-HFloat(0.31980563612041574)*exp(-HFloat(1.1646240098951652)*x)

 

 

a, b:=0, 2:
h:=0.1: n:=(b-a)/h;
X:=[seq(i*h,i=0..n)];
Y:=[seq(f1(i*h),i=0..n)];
F:=Statistics:-NonlinearFit(f2(x), X, Y, x);
plot([f1(x),F], x=0..2, color=[blue,red],legend=["f1","f2"]);

20.00000000

 

[0., .1, .2, .3, .4, .5, .6, .7, .8, .9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0]

 

[0., 0.5714285714e-1, .1000000000, .1333333333, .1600000000, .1818181818, .2000000000, .2153846154, .2285714286, .2400000000, .2500000000, .2588235294, .2666666666, .2736842106, .2800000000, .2857142858, .2909090910, .2956521740, .3000000000, .3040000000, .3076923076]

 

HFloat(0.31271326321044796)-HFloat(0.30377027346591473)*exp(-HFloat(1.6468916879789395)*x)

 

 

 


Edit.

Download nonlinfit2.mw

Here is another way. The first and second points almost coincide, so they block one another:

restart;
plot([[[28,.6481496576]],[[28, .648149657615473]],[[28, .6512873548]]],style='point',color=["Blue","Orange","Red"], symbol=solidcircle, symbolsize=12, labels = ["k", "y(k)"], legend = ["10-digit precision", "15-digit precision", "Floating-point iteration"] ,legendstyle = [font = ["HELVETICA", 9], location = right]);

                             

 

Use single quotes for single use (in 2d math only):

'a >= b'

                                  

Example:

-%int(x^2,x);

                                     

 

I think this is not a bug, but just such a design in Maple 2015. In subsequent versions of Maple, this command has been improved (the word  parameters  can be omitted). For example, in Maple 2018.2, the following code works correctly:

y := [1, 3, 8];
val := r->y[r]:
Explore(val(r), r=1..3);

 


 

diff(F(x(t),y(t)),t)=0;

(D[1](F))(x(t), y(t))*(diff(x(t), t))+(D[2](F))(x(t), y(t))*(diff(y(t), t)) = 0

(1)

 


 

Download diff.mw

In  display(L2,L22,L3,L1)  the previously recorded polygon  L2  closes the later recorded polygon  L22, but L1  and  L3  always lie higher (in Maple 2018.2). See the workaround below:

restart;
with(plots):
L1 := textplot([2, 2, "Polygon"], color = white, font=[times,bold,16]):
L2 := plottools:-polygon([[0, 0], [3, 4], [3, 1]], color = red):
L22 := plottools:-polygon([[0, 0], [0.5, 2], [1,0]], color = green):
L3 := contourplot(x^2 + y^2, x = 1 .. 1.5, y = 4/3*x..2):

display(L2,L22,L3,L1); 

                    

 

 

The  coords=polar  option doesn't seem to work (in Maple 2018.2), so I used Cartesian coordinates.
3 regions are plotted:

A:=plots:-inequal({sqrt(x^2+y^2)<2+2*x/sqrt(x^2+y^2),sqrt(x^2+y^2)>3},x=-3.3..4.3,y=-4.3..4.3, color=green):
B:=plots:-inequal({sqrt(x^2+y^2)>2+2*x/sqrt(x^2+y^2),sqrt(x^2+y^2)<3},x=-3.3..4.3,y=-4.3..4.3, color=blue):
C:=plots:-inequal({sqrt(x^2+y^2)<2+2*x/sqrt(x^2+y^2),sqrt(x^2+y^2)<3},x=-3.3..4.3,y=-4.3..4.3, color=red):
plots:-display(<A | B | C>, scaling=constrained);

             


 

We can get a general solution to your problem for an integer  n , if we first solve without initial conditions, and then impose these conditions and solve the corresponding system. We see that there is an infinite family of solutions  y(x)=C*sin(n*Pi*x)  (С is an any constant)  only if  A = 0. There are no any solutions if  A <> 0 .

restart;
ode := diff(y(x), x, x) + (n*Pi)^2*y(x) = A^3*sin(n*Pi*x)^3;
dsol1 := dsolve(ode);
Y:=eval(y(x),dsol1);
Sys:={eval(Y,x=0)=0, eval(Y,x=1)=0};
simplify(eval(op(2,Sys),_C1=0)) assuming n::integer;
solve(%, A,dropmultiplicity);

diff(diff(y(x), x), x)+n^2*Pi^2*y(x) = A^3*sin(n*Pi*x)^3

 

y(x) = sin(n*Pi*x)*_C2+cos(n*Pi*x)*_C1+(1/8)*(A^3*(cos(n*Pi*x)^2+2)*sin(n*Pi*x)-3*A^3*cos(n*Pi*x)*Pi*n*x)/(n^2*Pi^2)

 

sin(n*Pi*x)*_C2+cos(n*Pi*x)*_C1+(1/8)*(A^3*(cos(n*Pi*x)^2+2)*sin(n*Pi*x)-3*A^3*cos(n*Pi*x)*Pi*n*x)/(n^2*Pi^2)

 

{_C1 = 0, sin(n*Pi)*_C2+cos(n*Pi)*_C1+(1/8)*(A^3*(cos(n*Pi)^2+2)*sin(n*Pi)-3*A^3*cos(n*Pi)*Pi*n)/(n^2*Pi^2) = 0}

 

(3/8)*(-1)^(1+n)*A^3/(Pi*n) = 0

 

0

(1)

 


 

Download ode.mw

It is easy to achieve good visibility by simple means. I changed the style of the surfaces, removing the lines, each plane made in different colors and a few more minor changes. The solution itself is depicted as a bold red dot:

restart; with(plots):
sys := [p+x+.6*y-15, p+.3*x+.2*y-10, p+.5*x+y-14]:
sol:=solve(sys, [x, y, p])[];
A:=implicitplot3d(sys, x = 0 .. 10, y = 0 .. 10, p = 0 .. 10, style=surface, color=["LightBlue","LightGreen","Yellow"]):
B:=pointplot3d(eval([x,y,p],sol), color=red, symbol=solidsphere, symbolsize=15):
display(A,B, axes=normal, orientation=[-20,80], lightmodel=light4);

                   

 

 

 

Should be:

restart;

M:=Matrix(10, 10, [[1, 0, 0, 0, 1/2, 0, 0, 0, 0, 0], [0, 1/2, 0, 0, 0, 0, 0, 1/3, 0, 0], [0, 0, 1/2, 0, 0, 0, 0, 0, 1/3, 0], [0, 0, 0, 1/3, 0, 0, 0, 0, 0, 0], [1/2, 0, 0, 0, 1/3, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1/3, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1/4, 0, 0, 0], [0, 1/3, 0, 0, 0, 0, 0, 1/4, 0, 0], [0, 0, 1/3, 0, 0, 0, 0, 0, 1/4, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 1/4]]);

B:=Matrix(10, 5, [[0, 0, 1/3, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 1/4, 0, 0, 0], [0, 0, 1/4, 0, 0], [0, 0, 0, 1/4, 0], [1/2, 1/2, 1, 0, 0], [1, 1/2, 1/2, 1, 0], [0, 1, 1/2, 1/2, 1], [0, 0, 1, 1/2, 1/2]]);

B^%T.M^(-1).B;

 


 

restart;

Collocation:=proc(Equation,dependent_variable,range,N)
local x, _f, a, b, h, P, Eq1, x0, Sys;
x:=op(1,dependent_variable);
_f:=op(0,dependent_variable);
a:=op(1,rhs(range)); b:=op(2,rhs(range));
h:=(b-a)/N;
assign(seq(x0[i]=a+i*h, i=0..N));
P:=unapply(add(c[k]*x^k, k=0..N),x);
Eq1:=eval(Equation,_f=P);

Sys:={seq(eval(Eq1,x=x0[i]),i=0..N)};
solve(Sys,{seq(c[k],k=0..N)});
eval(`+`(seq(c[k]*x^k, k=0..N)), %);

end proc:

Example of use

Digits:=20:
# Solution by Collocation method
P:=unapply(Collocation(Z(x)=3/2-9/2*exp(-2*x)-9/2*exp(-x)+1/2*int(exp(-y)*Z(x-y),y=0..ln(2)),Z(x),x=1.5..3.5,10),x);

# Exact solution
F:=x->-9*exp(-2*x)+9*exp(-x)/(ln(2)-2)+2;

# Comparison of both solutions
plot([P,F],0..5, color=[red,blue]);
[seq(P(x)-evalf(F(x)), x=1.5..3.5,0.1)];

proc (x) options operator, arrow; -0.12331554479342308695e-4*x^10+0.38406523011732251249e-3*x^9-0.55359297313193274728e-2*x^8+0.48997335594780008876e-1*x^7-.29762100374551440593*x^6+1.3111429281362668287*x^5-4.3026456739050720369*x^4+10.574218375318812660*x^3-19.071575613482829384*x^2+23.489066676139941227*x-13.487137706256138762 end proc

 

proc (x) options operator, arrow; -9*exp(-2*x)+9*exp(-x)/(ln(2)-2)+2 end proc

 

 

[0.17326801985283735e-2, 0.12016434569748980e-2, 0.8333501267695410e-3, 0.5779327587865551e-3, 0.4008013985378725e-3, 0.27796169050566898e-3, 0.1927713461022417e-3, 0.1336897818009491e-3, 0.927151362940010e-4, 0.642987199705022e-4, 0.445920185728026e-4, 0.309253274978769e-4, 0.214470405083015e-4, 0.148735704742324e-4, 0.103151400046713e-4, 0.71541423541688e-5, 0.49611837817266e-5, 0.34390816064619e-5, 0.23860399357984e-5, 0.16643576852610e-5, 0.11482234181911e-5]

(1)

``

(2)

 


 

Download Collocation.mw

If you work in the real domain then replace  (y^3)^(2/3)  with  surd((y^3)^2, 3) (see help on the surd command for details). Then we see that the result is true for  y<0  as well:

expr:=-1/6*(y^6-6*y^3*ln(x)+9*ln(x)^2)*y^2/surd((y^3)^2,3);
simplify(expr) assuming y>0;
simplify(expr) assuming y<0;

                  

 

3 4 5 6 7 8 9 Last Page 5 of 227