Expt 2 Code Only
Expt 2 Code Only
Functions used
2.0 Appetizer
The function solve() will provide a general solution for symbolic equations. Let us start with roots of quadratic
equations. We shall provide a quadratic equation to matlab and it generates a symbolic values to the roots of
the equation.
syms a b c x s
eqn = a*x^2 + b*x + c == 0
s=solve(eqn)
We see it produces symbolic solution to quadratic equation. We can use solve() to generate symbolic
solution. Once the equation is generated, we can pass the values to the equation to get the exact value. We
use subs() to assign the variables to the equation. As shown here
%%
syms x
roots=solve(x^2 -7*x + 12,x)
1
Angle between radius vector and tangent is given by tan φ = r dθ/dr .
If tan φ1 and tan φ2 are angle between radius vector and tangent of two curves then |φ1 − φ2| is the angle
between two curves at the point of intersection.
2.1.1 Find the angle between the curves: r = 4*(1 + cos(t)) and r = 5*(1 − cos(t)).
%%
2.1.2 Find the angle between the curves r = 4*cos(t) and r = 5*sin(t)
syms r t
r1 = 4 * ( cos ( t ) ) ; % Define two curves
r2 = 5 * ( sin ( t ) ) ;
ezplot(r1)
hold on; ezplot(r2) % plot both the curves
dr1 = diff ( r1 , t ) %differntiate both the curves
dr2 = diff ( r2 , t )
figure() % plot the differentiated curves on a sperate window
ezplot(dr1)
hold on; ezplot(dr2)
t1 = r1 / dr1 % as in the previous example
t2 = r2 / dr2
q = solve ( r1 - r2 , t )
w1=subs(t1,vpa(q(1)));
w2=subs(t2,vpa(q(1)));
y1 = atan ( w1 ); % to find the inverse tan of w1
y2 = atan ( w2 );
w=abs(y1-y2) % you can use printf to print the result
2
2.2 Radius of curvature
Formula to calculate Radius of curvature in polar form is
syms t r a n
r = a * sin ( n * t ) ;
r1 = diff(r,t) ;
r2= diff(r1,t)
rho = (( r^2 + r1^2 )^(1.5))/ ( r^2 + 2 * r1^2 - r * r2 )
rho1 = subs(rho,t,pi/2)
rho2 = subs(rho1,n,1)
vpa(rho2)
3 Parametric curves
To find the radius of curvature equation is
With ' corresponding to first order and '' as second order differentiation
3
% perform algebraic simplification of the differentited functions
dydx = simplify(diff(y,t))/ simplify(diff(x,t) ) ;
rho = simplify((1 + dydx^2 )^(1.5)/(diff(dydx,t)/(diff(x,t)))) ;
display('radius of curvature:') ; vpa(rho)
% convert symbolic variable to a value using vpa() and display the same
t1 = pi / 2 ; % t=pi/2, as per the given expression
r1 = 5 ; % r= 5, as per the given expression