## 749 Reputation

11 years, 112 days

## use modular if...

if you just want to botain Pi/2 whenever x equals to zero, then you can use if conditional :

 > restart
 > f:=(x,y)->`if`(x=0,Pi/2,arctan(y/x))
 (1)
 > f(0,1)
 (2)
 > f(1,1)
 (3)
 > f(1,0)
 (4)

## using the formula...

as it is obvious from the diagrams, decreasing h leads to more accurate results.

 > restart:with(Student[Calculus1]):
 > ans:=dsolve([diff(y(t),t)=-cos(y(t))^2, y(0)=0]);
 (1)
 > f:=-cos(y(t))^2;
 (2)
 > trap:=proc(h,a,b,y0) local i, n,Y,A,p1,p2; n:=(b-a)/h; Y[1]:=y0: for i to n do Y[i+1]:=fsolve(MM=Y[i]+h/2*(eval(f,y(t)=Y[i])+eval(f,[y(t)=MM])),MM); od; A:=[seq](Y[i],i=1..n): p1:=plot([seq]([i/n,A[i]],i=1..n),axes=boxed,color=blue): p2:=plot(-arctan(t),t=0..1,color=green): plots:-display(p1,p2); end proc;
 (3)
 > for i in [0.1,0.01,0.001] do  trap(i,0,1,0) od;
 >
 >

## with a simple proc...

 > restart:
 > tangent:=proc(f,a) local Df,ans,b1; global L; # function in x #(a) the point in which the tangent line is plotted Df:=diff(f,x): b1:=solve((eval(f,x=a)=eval(diff(f,x)*x+b2,x=a)),b2); L:=eval(Df,x=a)*x+b1: print('L'=L); plot([f,L],x=-5+a..a+5,axes=boxed,gridlines): end proc:
 > tangent(x^2+3*x+1+20*sin(x)-log(x),2);
 >

## t*sin(t)...

The growth rate in every period is the difference of the blue points in the diagram.

 >
 > p1:=plot(x*sin(x),x=0..50):p2:=plot([seq]([Pi/2+2*i*Pi,Pi/2+2*i*Pi],i=0..7),style=point,color=blue):
 > plots:-display(p1,p2)
 >
 >

## use RealDomain...

 > restart
 > f:=(3*x^2+2*x-I)*(x+1)
 (1)
 > solve(f)
 (2)
 > RealDomain:-simplify(solve(f))
 (3)

## some suggestions...

I have some suggestions for you
for the first question, i think there is NOT as far as i know and only help documentation is availabe. and i think it is enough. since after having the initial knowlegde, rest of it is just using ordinary maple in Matlab interface.
for the second question, do NOT use symbolic computations with numeric ones in Matlab unless there is NOT another way. I have expericne on it and it is not a good way to do computations.
Good luck.

Edited.

## use equivalent form...

There is an equivalent form of variation of a functional in form of differentiation.
You can use this form to find variation of a functional with the corresponding boundary conditions.
but in this form, you should use physics package "diff" since you should differentiate with respect to another function.
see https://en.wikipedia.org/wiki/Euler–Lagrange_equation

## a procedure with random inputs...

 > restart:
 > P:=proc(f,n,a,b) local i,V; V:=LinearAlgebra:-RandomVector[row](n,generator=a..b,outputoptions=[datatype=float[8]]): seq(eval(f,x=(V[i])),i=1..n); end proc
 (1)
 > P(x^2+sin(x),5,1,10)
 (2)
 >

## you should have 2 variabels...

for using plot3d you shouldn't assign x1, and it should remain varibale to get a range. when u assing x1, you can just use plot

 > restart
 > f2:=3.579167+3.537500*x1-2.645833*x2-0.250000*x1*x1-0.012500*x2*x1+0.175000*x2*x2;
 (1)
 > plot3d (f2,x1=3..7 ,x2=3..7, axes=boxed);
 > x1:=5; f1:=3.579167+3.537500*x1-2.645833*x2-0.250000*x1*x1-0.012500*x2*x1+0.175000*x2*x2;
 (2)
 > plot (f1, x2=3..7, labels=[grape, preference], axes=boxed);
 >

## solve it using some assumptions...

i think the problem is due to maple can not determine the varibales sign in the "abs" function. so use assumptions to solve it :

 > restart
 > f:=sqrt(x)*ln(y);evalc(Im(f))
 (1)
 > solve(evalc(Im(f)), {x,y}) assuming x>0
 (2)
 > solve(evalc(Im(f)), {x,y}) assuming y>0
 (3)
 > g:=x*ln(y);evalc(Im(g))
 (4)
 > solve(evalc(Im(g)), {x,y})
 (5)
 >

## use select remove...

 > restart
 > A:=[ y[a0]-y[d0], k[d1]*y[a1]-k[d2]*y[d2], k[d1]*y[a1]*x[1]-k[d2]*y[d2]*x[2]];
 (1)
 > select(has,A,x);
 (2)
 > remove(has,A,x);
 (3)
 > #or select(has,A,[seq](x[i],i=1..2));
 (4)
 >

## it was better to upload the worksheet he...

it was better to upload the worksheet here, i think you should change " := " to " = " or bring the right hand side to the left with minus sign and without any " := " . i think it will work.

## another way using if condition ( just fo...

 > restart:printlevel:=2:
 > M:=5:
 > for i to M do if i<=M then N[i,0](u):=1;N[0,i](u):=0; fi;od;
 (1)
 >

## numerical solution...

here is a numerical solution based on the procedure on this link :
https://www.mapleprimes.com/questions/123970-Finding-All-Roots-For-An-ODE-In-A-Given-Interval

 > restart:
 > allRoots := proc(f :: procedure, rng :: range, \$) local result, root;   result := Vector(0, 'datatype = float');   root := RootFinding:-NextZero(f, lhs(rng), 'maxdistance' = rhs(rng) - lhs(rng));   while root <> FAIL and root <= rhs(rng) do     result(numelems(result) + 1) := root;     root := RootFinding:-NextZero(f, root, 'maxdistance' = rhs(rng) - root);   end do;   return result; end proc:
 > f:=proc(x) sin(sqrt(x));end proc
 (1)
 > allRoots(f,0..500)
 (2)
 >

## with some changes according to your comm...

 > restart:
 > EQ:=diff(C(t,r),t\$2)=(Z(r)^2-1)-(C(t,r)^2)/(4*alpha)*(1+((1+(16*(alpha)^2/C(t,r)^4)*(Z(r)^2-1)^2-(4*alpha*c/3)+(8*alpha*axi/C(t,r)^4)))^(1/2));
 (1)
 > pdsolve(EQ)
 (2)
 >
 >