mehdi jafari

764 Reputation

13 Badges

11 years, 226 days

MaplePrimes Activity


These are answers submitted by mehdi jafari

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))

proc (x, y) options operator, arrow; `if`(x = 0, (1/2)*Pi, arctan(y/x)) end proc

(1)

f(0,1)

(1/2)*Pi

(2)

f(1,1)

(1/4)*Pi

(3)

f(1,0)

0

(4)

NULL

Download arctan.mw

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]);

y(t) = -arctan(t)

(1)

f:=-cos(y(t))^2;

-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;

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]+(1/2)*h*(eval(f, y(t) = Y[i])+eval(f, [y(t) = MM])), MM) end do; 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;

 

 

 

 

 

 

 


 

Download trap.mw


 

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);

L = (13/2+20*cos(2))*x-2-40*cos(2)+20*sin(2)-ln(2)

 

 

 


 

Download tangent.mw

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

restart

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)

 

plots[animate](plot, [t*sin(t), t = 0 .. x], x = 0 .. 50)

 

NULL


 

Download MaplePrimes_Question.mw


 

restart

f:=(3*x^2+2*x-I)*(x+1)

(3*x^2+2*x-I)*(x+1)

(1)

solve(f)

-1, -1/3-(1/3)*(1+3*I)^(1/2), -1/3+(1/3)*(1+3*I)^(1/2)

(2)

RealDomain:-simplify(solve(f))

-1

(3)

``


 

Download solve.mw

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.

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
 


 

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

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)

HFloat(49.65698659871879), HFloat(49.65698659871879), HFloat(9.141120008059866), HFloat(35.72058450180107), HFloat(24.04107572533686)

(2)

 


 

Download proce.mw

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;

3.579167+3.537500*x1-2.645833*x2-.250000*x1^2-0.12500e-1*x2*x1+.175000*x2^2

(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;

5

 

15.016667-2.708333*x2+.175000*x2^2

(2)

 plot (f1, x2=3..7, labels=[grape, preference], axes=boxed);

 

 


 

Download plot.mw

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))

x^(1/2)*ln(y)

 

(1/2)*abs(x)^(1/2)*(1-signum(x))*ln(abs(y))+(1/2)*abs(x)^(1/2)*(1+signum(x))*(1/2-(1/2)*signum(y))*Pi

(1)

solve(evalc(Im(f)), {x,y}) assuming x>0

{x = 0, y = y}, {x = x, 0 <= y}

(2)

solve(evalc(Im(f)), {x,y}) assuming y>0

{x = x, y = 1}, {y = y, 0 <= x}, {x = 0, 0 < y}

(3)

g:=x*ln(y);evalc(Im(g))

x*ln(y)

 

x*(1/2-(1/2)*signum(y))*Pi

(4)

solve(evalc(Im(g)), {x,y})

{x = 0, y = y}, {x = x, 0 <= y}

(5)

 


 

Download assum.mw


 

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]];

[y[a0]-y[d0], k[d1]*y[a1]-k[d2]*y[d2], k[d1]*x[1]*y[a1]-k[d2]*x[2]*y[d2]]

(1)

select(has,A,x);

[k[d1]*x[1]*y[a1]-k[d2]*x[2]*y[d2]]

(2)

remove(has,A,x);

[y[a0]-y[d0], k[d1]*y[a1]-k[d2]*y[d2]]

(3)

#or
select(has,A,[seq](x[i],i=1..2));

[k[d1]*x[1]*y[a1]-k[d2]*x[2]*y[d2]]

(4)

 


 

Download select.mw

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.


 

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

 

0

 

1

 

0

 

1

 

0

 

1

 

0

 

1

 

0

(1)

 


 

Download another_way.mw

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

proc (x) sin(sqrt(x)) end proc

(1)

allRoots(f,0..500)

Vector(7, {(1) = 9.86960440100000, (2) = 39.4784176000000, (3) = 88.8264396000000, (4) = 157.913670400000, (5) = 246.740110000000, (6) = 355.305758400000, (7) = 483.610615600000})

(2)

 

NULL


 

Download allroots.mw

@Preben Alsholm 
 

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));

diff(diff(C(t, r), t), t) = Z(r)^2-1-(1/4)*C(t, r)^2*(1+(1+16*alpha^2*(Z(r)^2-1)^2/C(t, r)^4-(4/3)*alpha*c+8*alpha*axi/C(t, r)^4)^(1/2))/alpha

(1)

pdsolve(EQ)

C(t, r) = RootOf(-6*Intat(alpha/(-6*alpha*(-12*Z(r)^2*_g*alpha+3^(1/2)*(Int(((-4*alpha*c*_g^4+48*Z(r)^4*alpha^2+3*_g^4-96*Z(r)^2*alpha^2+48*alpha^2+24*alpha*axi)/_g^4)^(1/2)*_g^2, _g))+12*_g*alpha-6*_F1(r)*alpha+_g^3))^(1/2), _g = _Z)+t+_F2(r))

(2)

 

 


 

Download pdsolve.mw

dear saba, is this what you want ?

1 2 3 4 5 6 7 Last Page 1 of 9