Kitonum

21530 Reputation

26 Badges

17 years, 92 days

MaplePrimes Activity


These are replies submitted by Kitonum

@Carl Love I understand very well that my procedure can be improved both in terms of its effectiveness and length. But there are also pedagogical considerations. You can see for yourself that OP is a complete newbie to coding. My goal was to make minimal changes to the code to make it work and at the same time maintain the overall intent of the person who wrote the code. It is great that you are always looking for the best solutions. At the same time, I think it is not entirely ethical to speak out here about the vote.

@maxprog I beg your pardon. I do not have a maple calculator.

What does  2 z y =  mean?

@nm  There are 2 problems with this example:
1. The  indets  command for some reason does not consider  sqrt  as a function.
2. Maple unusually returns the result if any real number is the solution. It just returns  x  instead of  RealRange(-infinity,infinity) .

The following code handles these situations:

restart;
ode:=diff(y(x),x)-y(x) = x*y(x)^(1/2);
ic:=y(0)=4;

#this below code from https://www.mapleprimes.com/questions/231328-How-To-Make-Solve-Obtain-All-Values

sol:=dsolve([ode,ic],y(x));
res:=odetest(sol,ode);
F:=indets(res, function); # The function sqrt is missing
F:=F union indets(res,sqrt);
R:=[solve(`and`(seq(`or`(F[i]>0, F[i]<0, F[i]=0), i=1..nops(F))))];
if R=[x] then R:=[RealRange(-infinity,infinity)] fi;
solve(res) assuming `or`(seq(x in R[i],i=1..nops(R)));

 

@nm  Take a look at the update to my answer above. This same way solves your last example:

restart;
ode:=diff(y(x),x)=2*(x*sqrt(y(x))-1)*y(x):
ic:=y(0) = 1:
sol:=dsolve([ode,ic],y(x));
res:=odetest(sol,ode);
F:=indets(res, function);
R:=[solve(`and`(seq(`or`(F[i]>0, F[i]<0, F[i]=0), i=1..nops(F))))];
solve(res) assuming `or`(seq(x in R[i],i=1..nops(R)));

 

@nm  Very often you have to help Maple to achieve your goal. In this example, the assumption  x>0   is natural, since  x>0  is the domain for the function  ln(x)  in the real domain.

@DanishMapleFan  If the polynomials  h  and  g  are given, then you can use the method of undefined coefficients to reduce the problem to solving a system of linear equations.

The same example (without compoly):

restart;

g:=unapply((x+1)^2, x);
f:=unapply(2*x^2+x+3, x);
h:=expand((f@g)(x));
F:=unapply(a*x^2+b*x+c, x);
Eq:=expand((F@g)(x))=h;

Sys:={seq(coeff(lhs(Eq),x,n)=coeff(rhs(Eq),x,n), n=0..4)};
solve(Sys);
assign(%);

is(F(x)=f(x));

   

@nm  I do not understand at all what is the point of applying the  solve  command to a differential equation. Below are two very simple examples (which essentially mean the same thing). The output of the second example seems to me incorrect:

solve(y(x)+diff(y(x),x)=0, y(x)); # example 1
solve(y(x)+D(y)(x)=0, y(x)); # example 2

  

@AHSAN   depends on the width of the plot and is controlled by Maple automatically (see 2 examples below). Try playing with the options  size  for the plot  and  font  for legends. I don't know how to control  the width of legends box programmatically:

restart;
v := a+2*H*Q/T; 
v := subs(H = T*x, v);

plot([subs(a = 0.1, Q = 0.5, v), subs(a = 0.2, Q = 0.4, v)], x = 1 .. 10, style = pointline, colour = [black, red], symbol = [solidcircle, asterisk], symbolsize = 15, axes = boxed, numpoints = 20, legend=["a = 0.1, Q = 0.5 ", "a = 0.2, Q = 0.4"], legendstyle=[location=top],size=[400,400]); #example 1

plot([subs(a = 0.1, Q = 0.5, v), subs(a = 0.2, Q = 0.4, v)], x = 1 .. 10, style = pointline, colour = [black, red], symbol = [solidcircle, asterisk], symbolsize = 15, axes = boxed, numpoints = 20, legend=["a = 0.1, Q = 0.5 ", "a = 0.2, Q = 0.4"], legendstyle=[location=top],size=[250,400]); #example 2

 

@AHSAN  As you yourself mentioned, only  4 positions are available (in the example below, all the legends on the right). Therefore, if none of these options suits you, then this problem cannot be solved using the  legend  option.

restart;
v := a+2*H*Q/T; 
v := subs(H = T*x, v);

plot([subs(a = 0.1, Q = 0.5, v), subs(a = 0.2, Q = 0.4, v), subs(a = 0.3, Q = 0.35, v), subs(a = 0.4, Q = 0.3, v)], x = 1 .. 10, colour = [black, red, blue, green], axes = boxed);
 
plot([subs(a = 0.1, Q = 0.5, v), subs(a = 0.2, Q = 0.4, v)], x = 1 .. 10, style = pointline, colour = [black, red], symbol = [solidcircle, asterisk], symbolsize = 15, axes = boxed, numpoints = 20, legend=["a = 0.1, Q = 0.5", "a = 0.2, Q = 0.4"], legendstyle=[location=right]);

 

@AHSAN  Below the example of legends for the second plot. The same can be used for the first plot:

restart;
v := a+2*H*Q/T; 
v := subs(H = T*x, v);

plot([subs(a = 0.1, Q = 0.5, v), subs(a = 0.2, Q = 0.4, v), subs(a = 0.3, Q = 0.35, v), subs(a = 0.4, Q = 0.3, v)], x = 1 .. 10, colour = [black, red, blue, green], axes = boxed);
 
plot([subs(a = 0.1, Q = 0.5, v), subs(a = 0.2, Q = 0.4, v)], x = 1 .. 10, style = pointline, colour = [black, red], symbol = [solidcircle, asterisk], symbolsize = 15, axes = boxed, numpoints = 20, legend=["a = 0.1, Q = 0.5", "a = 0.2, Q = 0.4"]);


Edit.

@tomleslie Thank you! I did not know about it. The good workaround.

@lcz  Yes, I know, but this is the simplest solution to the problem for older versions of Maple. I think that this is quite possible to put up with. `3`!  is not calculated because  `3`  is not an integer but just a symbol. 

@mmcdara  I didn't understand where this error came from. I saved my worksheet again and downloaded it. Everything seems to be working correctly now.

@nm  OP just missed the  seq  command when copying.

First 16 17 18 19 20 21 22 Last Page 18 of 133