Kitonum

21952 Reputation

26 Badges

17 years, 326 days

MaplePrimes Activity


These are answers submitted by Kitonum

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;

                  

 


This can be done in many ways. Here are 2 ones:

restart;
a1 := 5; b1 := 3; a2 := 3; b2 := 4; a3 := 3; b3 := 7;
eq1 := expand((y-2)^2/b1^2+(x-5)^2/a1^2 = 1):
eq2 := expand((y+2)^2/b2^2+(x+1)^2/a2^2 = 1):
Sys := {eq1, eq2};
Sol := [solve(Sys, explicit)]:
Sol1:=evalf(Sol);
L := remove(has, Sol1, I);

5

 

3

 

3

 

4

 

3

 

7

 

{(1/9)*y^2-(4/9)*y+13/9+(1/25)*x^2-(2/5)*x = 1, (1/16)*y^2+(1/4)*y+13/36+(1/9)*x^2+(2/9)*x = 1}

 

[{x = -5.904184041+4.979964478*I, y = 5.276003264+5.967296157*I}, {x = -5.904184041-4.979964478*I, y = 5.276003264-5.967296157*I}, {x = 0.15513671e-1, y = 1.763859011}, {x = 1.698810533, y = -.253169615}]

 

[{x = 0.15513671e-1, y = 1.763859011}, {x = 1.698810533, y = -.253169615}]

(1)

RealDomain:-solve(Sys);
evalf(%);

{x = RootOf(101761*_Z^4+1027180*_Z^3+4013700*_Z^2-10376000*_Z+160000, 0.1551366944e-1), y = -(319/1800)*RootOf(101761*_Z^4+1027180*_Z^3+4013700*_Z^2-10376000*_Z+160000, 0.1551366944e-1)^2-(161/180)*RootOf(101761*_Z^4+1027180*_Z^3+4013700*_Z^2-10376000*_Z+160000, 0.1551366944e-1)+16/9}, {x = RootOf(101761*_Z^4+1027180*_Z^3+4013700*_Z^2-10376000*_Z+160000, 1.698810530), y = -(319/1800)*RootOf(101761*_Z^4+1027180*_Z^3+4013700*_Z^2-10376000*_Z+160000, 1.698810530)^2-(161/180)*RootOf(101761*_Z^4+1027180*_Z^3+4013700*_Z^2-10376000*_Z+160000, 1.698810530)+16/9}

 

{x = 0.1551366944e-1, y = 1.763859010}, {x = 1.698810530, y = -.253169614}

(2)

 


 

Download RealSol.mw

We can easily get the answer in a closed form if we use  rsolve  command. To remove the sign of the sum, it is necessary to split this sum into 3 terms:


 

restart;
u := unapply(simplify(value(rsolve({u(1) = 1, u(n+1) = a*u(n)+b[irem(n, 3)]}, u(n)))), n);
U := n->a^(n-1)+sum(a^(n-2-3*k), k = 0 .. floor((n-2)*(1/3)))*b[1]+sum(a^(n-3-3*k), k = 0 .. floor((n-3)*(1/3)))*b[2]+sum(a^(n-4-3*k), k = 0 .. floor((n-4)*(1/3)))*b[0];

 

proc (n) options operator, arrow; a^(n-1)+sum(a^(n-n0)*b[irem(n0-1, 3)], n0 = 2 .. n) end proc

 

proc (n) options operator, arrow; a^(n-1)+(sum(a^(n-2-3*k), k = 0 .. floor((1/3)*n-2/3)))*b[1]+(sum(a^(n-3-3*k), k = 0 .. floor((1/3)*n-1)))*b[2]+(sum(a^(n-4-3*k), k = 0 .. floor((1/3)*n-4/3)))*b[0] end proc

(1)

V:=normal~(U(n)); # The result in a closed form (without sum)

-(a^(n-4)*a^3*b[0]*(1/a^3)^(floor((1/3)*n+2/3)-1)+a^(n-2)*a^3*b[1]*(1/a^3)^floor((1/3)*n+1/3)+a^(n-3)*a^3*b[2]*(1/a^3)^floor((1/3)*n)-a^(n-4)*a^3*b[0]-a^(n-2)*a^3*b[1]-a^(n-3)*a^3*b[2]-a^(n-1)*a^3+a^(n-1))/(a^3-1)

(2)

# Examples:
seq(u(n), n = 1 .. 10);
seq(U(n), n = 1 .. 10);

eval(V,[a=5,n=100]);
 

1, a+b[1], a^2+a*b[1]+b[2], a^3+a^2*b[1]+a*b[2]+b[0], a^4+a^3*b[1]+a^2*b[2]+a*b[0]+b[1], a^5+a^4*b[1]+a^3*b[2]+a^2*b[0]+a*b[1]+b[2], a^6+a^5*b[1]+a^4*b[2]+a^3*b[0]+a^2*b[1]+a*b[2]+b[0], a^7+a^6*b[1]+a^5*b[2]+a^4*b[0]+a^3*b[1]+a^2*b[2]+a*b[0]+b[1], a^8+a^7*b[1]+a^6*b[2]+a^5*b[0]+a^4*b[1]+a^3*b[2]+a^2*b[0]+a*b[1]+b[2], a^9+a^8*b[1]+a^7*b[2]+a^6*b[0]+a^5*b[1]+a^4*b[2]+a^3*b[0]+a^2*b[1]+a*b[2]+b[0]

 

1, a+b[1], a^2+a*b[1]+b[2], a^3+a^2*b[1]+a*b[2]+b[0], a^4+(a^3+1)*b[1]+a^2*b[2]+a*b[0], a^5+(a^4+a)*b[1]+(a^3+1)*b[2]+a^2*b[0], a^6+(a^5+a^2)*b[1]+(a^4+a)*b[2]+(a^3+1)*b[0], a^7+(a^6+a^3+1)*b[1]+(a^5+a^2)*b[2]+(a^4+a)*b[0], a^8+(a^7+a^4+a)*b[1]+(a^6+a^3+1)*b[2]+(a^5+a^2)*b[0], a^9+(a^8+a^5+a^2)*b[1]+(a^7+a^4+a)*b[2]+(a^6+a^3+1)*b[0]

 

12723562987435674280834331698109455317309781211435854915649660172001*b[0]+318089074685891857020858292452736382932744530285896372891241504300025*b[1]+63617814937178371404171658490547276586548906057179274578248300860005*b[2]+1577721810442023610823457130565572459346412870218046009540557861328125

(3)

 


Edit.

Download seq1.mw

First 69 70 71 72 73 74 75 Last Page 71 of 292