a:=x^3+2*x^2+3*x-6; b:=x^3+3*x^2+7*x+5; f:=a/b; solve(a=0,x); solve(b=0,x); solve(diff(f,x)=0,x); the problem is that solve might not work. if so, use fsolve(a=0,x); (or fsolve(a=0,x,complex); to find also complex roots). Similarly for the other equations.
create the following m-file:
targ2.m
-------
function z=targ2(x,y)
z=zeros(size(x));
for i=1:size(x,1)
for j=1:size(x,2)
if (x(i,j)>0 & y>0 & x(i,j)^4+y^2<1)
z(i,j)=(x(i,j)+y)/(1+x(i,j)^2+y^2);
end
end
end
then run the following command:
dblquad(@targ2,0,1,0,1)
with(LinearAlgebra)
m:=<<1,2>|<2,t>>;
e:=Eigenvalues(m);
plot( {e[1],e[2]}, t=-5..5);
t=[-5:0.1:5];
for i=1:size(t,2)
m(:,i)=eig([1,2;2,t(i)]);
end
hold on
plot(t,m(1,:))
plot(t,m(2,:))
with(LinearAlgebra): c:=cos(sqrt(1+t^2)); s:=sin(sqrt(1+t^2)); g:=<<c,-s>|<s,c>>; h:=Matrix(2); for i from 1 to 2 do for j from 1 to 2 do h[i,j]:=diff(g[i,j],t); end do: end do: evalf(int( Trace(g.h.g.h), t=0..1));
create the following m-file:
a6.m
----
function y=a6(x,p)
y=x^2/2+1-cos(x)+1/(1+p*x^2);
then run the following commands:
p=[1:0.01:2];
for i=1:101
[y,q(i)]=fminsearch(@a6,0,[],p(i));
end
plot(p,q)
with(LinearAlgebra);
M:=<< 1,-2,-4 >|< s,t,u>|<-2,2,-3>> ;
cp:=CharacteristicPolynomial(M,lambda);
solve({subs(lambda=1,cp)=0,subs(lambda=2,cp)=0,subs(lambda=3,cp)=0},{s,t,u});
with(LinearAlgebra);
M:=<< 1,-2,-4 >|< s,2,4>|<-2,2,-3>> ;
s0:=solve( Determinant(M)=0, s);
N:=subs(s=s0,M);
cs:=ColumnSpace(N);
take c in the column space (for example c:=op(1,cs))
and b not in the column space
function ans2(c,d)
as=roots(d);
a=-10; % can use -Inf
b=10; % can use Inf
for i=1:size(as,1)
if imag(as(i))==0
if (as(i)<0 & as(i)>a)
a=as(i);
end
if (as(i)>0 & as(i)<b)
b=as(i);
end
end
end
a % the largest negative asymptote
b % the smallest positive asymptote
% plotting the graph - 50 points
h=(b-a)/51;
x=a+[1:50]*h;
deno=0;
for i=1:size(d,2)
deno=deno.*x+d(i)*ones(1,50);
end
nume=0;
for i=1:size(c,2)
nume=nume.*x+c(i)*ones(1,50);
end
plot(x, nume./deno)
% must be careful there could be an asymptote at 0
% it is better to check this by looking whether d(m)==0
% to find the critical points - A simple way is to locate them
% on the graph and then use fminsearch. Or it is possible to
% compute the coefficients of c'd-d'c and then use "roots".
with(LinearAlgebra):
ccl:=proc(a,b,c,d)
local M;
M:=<b-a|c-a|d-a>;
if (Determinant(M)=0) then return(1) else return(0) end if;
end proc;
ccc:=proc(a,b,c,d)
local z1,z2,z3,z4,cr;
z1:=a[1]+I*a[2];
z2:=b[1]+I*b[2];
z3:=c[1]+I*c[2];
z4:=d[1]+I*d[2];
cr:=(z1-z2)*(z3-z4)/(z1-z4)/(z3-z2);
if (Im(cr)=0) then return(1) else return(0) end if;
end proc;
% putting them together: the a,b,c,d of the first program
% are 3-dimensional, in the second program they are 2-dim.
% here is a way to do it, without explanation:
cc:=proc(a,b,c,d)
local v,v1,v2,A,B,C,D;
if (cc1(a,b,c,d)=0) then return(0)
else v1:=(b-a)/Norm(b-a,2);
v:=(c-a)-((c-a).v1)*v1;
v2:=v/Norm(v,2);
A:=<0,0>;
B:=<(b-a).v1,(b-a).v2>;
C:=<(c-a).v1,(c-a).v2>;
D:=<(d-a).v1,(d-a).v2>;
if (ccc(A,B,C,D)=0) then return(0)
else return(1);
end if;
end if;
end proc;
Back to course homepage
Back to my main teaching page
Back to my main page