Kitonum

21440 Reputation

26 Badges

17 years, 37 days

MaplePrimes Activity


These are answers submitted by Kitonum

f:=x->1/(1+x^2):
f1:=[[0,f(0)], [1/3,f(1/3)]]:
f2:=[[1/3,f(1/3)], [2/3,f(2/3)]]:
f3:=[[2/3,f(2/3)], [1,f(1)]]:
plot([f(x), f1, f2, f3], x=0..1, color=[red,blue,green,black], view=[0..1,0..1], legend=['f','f1','f2','f3']);


In your question, you wrote  f(x)=1/1+x^2. But this is just  f(x)=1+x^2 . Therefore, I assumed that the parentheses are omitted.


Addition. If you want all functions to be plotted on the same interval  0 .. 1 , then do so:

f:=x->1/(1+x^2):
g:=(x1,y1,x2,y2)->y1+(y2-y1)*(x-x1)/(x2-x1):
f1:=g(0,f(0),1/3,f(1/3)):
f2:=g(1/3,f(1/3),2/3,f(2/3)):
f3:=g(2/3,f(2/3),1,f(1)):
plot([f(x), f1, f2, f3], x=0..1, color=[red,blue,green,black], view=[0..1,0..1.2], legend=['f','f1','f2','f3']);


Edit.
 

Should be

plot(eval([(exp((1/2)*x))*((1/2)*x+2*t*(1/3)), (exp((1/2)*x))*(1+t((-256)+240-108+27)/2^7+t(168-24+27)^2/2^7+(1/3)*t^3*((-16)+9)/2^6+(1/4)*t^4/2^7), (exp((1/2)*x))*(1+t(256*(-1.01)+240*(-1.01)^2+108*(-1.01)^3+27*(-1.01)^4)/2^7+t(168*(-1.01)^2+24*(-1.01)^3+27*(-1.01)^4)^2/2^7+(1/3)*t^3*(16*(-1.01)^3+9*1.01^4)/2^6+(1/4)*t^4*(-1.01)^4/2^7)], t=5), x = -4 .. 4);


Edit.

This can be done in several ways. The shortest one:

G := {A=exp1, B=exp2}:
assign(G);

A, B;

                                      exp1, exp2

If  alpha  occurs not in one, but in several places at once, then it is more convenient to use freeze  and  thaw commands.

Example:

restart;
expr:=-sin(alpha)*(sin(theta1)*cos(theta)-cos(theta1)*sin(theta))+2*cos(alpha)*sin(theta)*cos(theta):
combine(subs([sin(alpha)=freeze(sin(alpha)), cos(alpha)=freeze(cos(alpha))], expr)):
thaw(%);

                              sin(alpha)*sin(-theta1+theta)+cos(alpha)*sin(2*theta)

Obviously this is a bug. The problem (assuming all variables should be binary) is easily solved by simple code in a for loop:

Max:=-infinity:
for x__1 from 0 to 1 do
for x__2 from 0 to 1 do
for x__3 from 0 to 1 do
for x__4 from 0 to 1 do
for x__5 from 0 to 1 do
if 3*x__1+5*x__2+6*x__3+2*x__4+x__5 <= 10 then M:=3*x__1+14*x__2+18*x__3+6*x__4+2*x__5;
if M>Max then S:=[[x__1,x__2,x__3,x__4,x__5], M]; Max:=M fi;fi;
od: od: od: od: od:
S;

                                                  [[0, 0, 1, 1, 1], 26]


Here's another way to solve the same problem (more compact method suitable for more variables):

P:=combinat:-permute([0$5,1$5], 5):
Z:=(x__1,x__2,x__3,x__4,x__5) -> 3*x__1+14*x__2+18*x__3+6*x__4+2*x__5:
f:=(x__1,x__2,x__3,x__4,x__5) -> 3*x__1+5*x__2+6*x__3+2*x__4+x__5:
[seq(`if`(f(p[])<=10, [p, Z(p[])], NULL), p=P)]:
sort(%, (a,b)->a[-1]>b[-1])[1];

                                                   [[0, 0, 1, 1, 1], 26]


The third workaround is Mariusz Iwaniuk's way from here to increase  Digits :

restart;
Digits:=20:
Optimization:-LPSolve(3*x__1+14*x__2+18*x__3+6*x__4+2*x__5, {3*x__1+5*x__2+6*x__3+2*x__4+x__5 <= 10}, x__1 = 0 .. 1, x__2 = 0 .. 1, x__3 = 0 .. 1, x__4 = 0 .. 1, x__5 = 0 .. 1, assume=binary, maximize);

                           [26, [x__1 = 0, x__2 = 0, x__3 = 1, x__4 = 1, x__5 = 1]]

 

Edit.

Maybe you want it:

A:=Matrix(2, 2, {(1, 1) = (1/6)*sqrt(3)+(1/2)*I, (1, 2) = (1/6)*sqrt(3)-(1/2)*I, (2, 1) = (1/6)*sqrt(3)-(1/2)*I, (2, 2) = (1/6)*sqrt(3)+(1/2)*I});
A1:=(sqrt(3)/6)%*(Matrix(2,(i,j)->Re(A[i,j]))/(sqrt(3)/6))%+((1/2)%*(Matrix(2,(i,j)->A[i,j]-Re(A[i,j]))/(1/2)));   
# Or
A2:=(sqrt(3)/6)%*(Matrix(2,(i,j)->Re(A[i,j]))/(sqrt(3)/6))%+((1/2)%*(Matrix(2,(i,j)->Im(A[i,j]))/(1/2))%*I);

              

 

 

 

If you want to calculate the values of an expression for different values of a variable, it is convenient to immediately specify it as a function, and not as an expression. Then in the future it will be very easy to calculate the value of this function symbolically or numerically.

Your example:
f := x->2*sin(x)-x^2/10:
f(5),  f(5.);
                                   
2*sin(5)-5/2,  -4.417848549                    

Here are 3 ways to solve the problem by an example.

The problem: find the smallest root of equation  sin(100*x)+0.1*x=0  in the range  1 .. 2 . In this range there are several dozen roots.

The first way by  fsolve  command. Using  plot  command, we reduce the range to a single root:

restart;
eq:=sin(100*x)+0.1*x=0:
fsolve(sin(100*x)+0.1*x=0, x = 1 .. 2);
plot(lhs(eq), x = 1 .. 2);
plot(lhs(eq), x = 1 .. 1.1);
fsolve(lhs(eq), x = 1 .. 1.02);


The second way by  RootFinding:-Analytic  command, which provides all the real and complex roots in the range  re=1..2, im=-1..1  and we select the smallest real one:

[RootFinding:-Analytic(lhs(eq), re=1..2, im=-1..1)];
min(%);


The third way by  Student:-Calculus1:-Roots  command, which provides all the real roots in this range and we select the smallest one:

evalf(Student:-Calculus1:-Roots(lhs(eq), x = 1 .. 2));
min(%);




 

 

One solution we can get by  fsolve  command:

fsolve({x^2 + y^2 + z^2 = 4, x + y + z = 0, x*sin(y*z) = -1});
                                 
{x = -1.630958259, y = 0.8860579420, z =0 .7449003167}


The plots shows that there are 2 real solutions (I eliminated z-variable from the system):
plots:-implicitplot([x^2 + y^2 + (-x-y)^2 = 4, x*sin(y*(-x-y)) = -1], x=-3..3, y=-3..3, color=[red,blue], gridrefine=5):
plots:-implicitplot([x^2 + y^2 + (-x-y)^2 = 4, x*sin(y*(-x-y)) = -1], x=-1.7..-1.2, y=0.5..1, color=[red,blue], gridrefine=5):
plots:-display(<%% | %>);

The second solution:
fsolve({x^2 + y^2 + z^2 = 4, x + y + z = 0, x*sin(y*z) = -1}, {x=-1.7..-1.6,y=0.7..0.8, z=0..1});
                   
 {x = -1.630958259, y = 0.7449003167, z =0.8860579420}

                
Edit.

 

 

Use  RealDomain:-solve  instead of  solve . See the corrected file:

mathias1.mw 

You did not write how many values of  a  we should consider, so I took  a=1  and  a=2  only:

seq([fsolve(x^3 - a*x + 1 = 0)], a=1..2);  # All the real roots
plot([seq(x^3 - a*x + 1, a=1..2)], x=-2..2, -2..3, color=[red,blue]);  # The corresponding plots 

       

Because of your 2d-mode, we can not determine which commands you use. 1d mode explains the difference:

sum(beta__i, i = 0 .. 2); 
sum(beta[i], i = 0 .. 2);

                              


 

de := 100*diff(v(t),t)=100*9.81-k*v(t);
inc:=v(0)=0;
sol:=dsolve({de, inc}, v(t));
k=solve(limit(rhs(sol), t=infinity)=5, k)
assuming k>0;
evalf(%);
plot([5, eval(rhs(sol),%)], t=0..5, linestyle=[3,1], thickness=[0,2], color=[black,red], labels=[t,v(t)], labelfont=[times,bold, 16], size=[800,300]);

        
     
We see that for  t>3  the speed  v(t)  is practically equal to  5 . 


Edit.                   

Q:=[]:
for i from 1 by 1 to 3 do 
simplfloat:=rand(-1.0..1.0): 
a:=simplfloat():     
eq:=a+i:
Q:=[op(Q),[i,a,eq]]:
end do:
writedata("all.dat", Q):

 

We can make a simple visual qualitative analysis of this equation if we rewrite it in the form  c=f(x)  (vv's nice idea) . Using the graphical interpretation, it is easy to see how many real roots this equation has, depending on the value of the parameter . The numbers  x0  and  y0  are the coordinates of the red point.

c=expand(solve(10*c*x^7-6*x^3+6=0, c));
f:=rhs(%):
solve({diff(f,x)=0, x>0}, explicit):
x0:=eval(x, %);
y0:=eval(f, x=x0);
plots:-display(plot(f, x=-3..3, -0.1..0.2, color=blue, discont, size=[500,350], labels=[x,c]), plot([[x0,y0]], style=point, color=red, symbol=solidcircle, symbolsize=12));

     

Based on the properties of the function  x->3/(5*x^4)-3/(5*x^7)  and its plot, the following conclusions can be drawn:

1.If  c<0, there is the unique positive solution that tends to   if c tends to .
2. If  c=0, there is the unique solution  x=1 .
3. If  0<c<36*14^(2/3)*(1/1715), there are 3 solutions. If  c  tends to  0, then one of them tends to  -infinity, the second to 1, and the third to  + infinity
4. If  с=36*14^(2/3)*(1/1715), there are 2 solutions: x=(1/2)*14^(1/3)  and the unique solution <0 .
5. If  c<36*14^(2/3)*(1/1715)  there are  the unique  solution  <0 .


The following simple procedure numerically finds a sorted list of all real roots for any given value c .

RealRoots:=proc(c)
uses RealDomain;
sort([evalf(solve(10*c*x^7-6*x^3+6=0))]);
end proc:


Examples of use:

 seq(RealRoots(c), c=-0.2..0.2, 0.01);  # All the real roots in the range -0.2..0.2 when  c  changes with the step 0.01
map(s->select(`>`, s, 0), [%]);  
# Only the positive roots


   
 

First 137 138 139 140 141 142 143 Last Page 139 of 289