0% found this document useful (0 votes)
3 views

AKSHAY Assignment - 03

The document contains a MATLAB assignment focused on symbolic computation and solving differential equations. It includes various examples of defining symbolic variables, performing differentiation, and solving ordinary differential equations (ODEs) with initial conditions. Additionally, it provides exercises for students to apply their understanding of the concepts covered.

Uploaded by

akshayappana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

AKSHAY Assignment - 03

The document contains a MATLAB assignment focused on symbolic computation and solving differential equations. It includes various examples of defining symbolic variables, performing differentiation, and solving ordinary differential equations (ODEs) with initial conditions. Additionally, it provides exercises for students to apply their understanding of the concepts covered.

Uploaded by

akshayappana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Satya Naga Akshay Appana

Section:CSE*C

JUUG24BTECH20913

Assignment - 03

Examples:

x=sym('x')

x =

yy=sym('yy')

yy =

c=sym(2)

c =

d=sym(8)

d =

e=13

e =
13

syms y z d
y

y =

syms a b c x y
f=a*x^2+b*x+c

f =

syms a x
g=2*a/3+4*a/7-6.5*x+x/3+4*5/3-1.5

g =

a=sym(3); b=sym(5);
e=b/a+sqrt(2)

e =

1
c=3; d=5;
f=d/c+sqrt(2)

f =
3.0809

syms a b c x
s=sqrt(a*x^2+b*x+c)

s =

pretty(s)

2
sqrt(a x + b x + c)

syms x y
s=(x^2+5*x+6)/(x+2);
sa=simplify(s)

sa =

diff(sin(x))

ans =

diff(cos(x))

ans =

diff(tan(x))

ans =

diff(cot(x))

ans =

diff(sec(x))

ans =

diff(csc(x))

ans =

2
diff(log(x))

ans =

diff(exp(x))

ans =

diff(asin(x))

ans =

diff(acos(x))

ans =

diff(atan(x))

ans =

diff(acot(x))

ans =

diff(asec(x))

ans =

diff(acsc(x))

ans =

3
diff(sinh(x))

ans =

diff(cosh(x))

ans =

diff(tanh(x))

ans =

diff(sech(x))

ans =

diff(csch(x))

ans =

syms x
s=sin(x);
diff(s)

ans =

cos(x)

ans =

s1=cos(x)

s1 =

diff(s1)

ans =

syms x y t
s=exp(x^4)

s =

diff(s)

4
ans =

diff((1-4*x)^3)

ans =

R=5*y^2*cos(3*t)

R =

diff(R)

ans =

diff(R,t)

ans =

s=exp(x^4)

s =

diff(s,2)

ans =

diff(diff(s))

ans =

diff(R,t,2)

ans =

T=x*sin(x*t);
diff(T,x,3)

ans =

a=5; x=2; y=8;


y=exp(-a)*sin(x)+10*sqrt(y)

y =
28.2904

MATLAB Code:

5
syms x(t) y(t)
A = input('Coefficient Matrix');
[V, D]=eig(A);
Eigen_Values=diag(D)

Eigen_Values = 2×1
-0.8990
8.8990

Y=[x; y];
odes = diff(Y) == A*Y

odes(t) =

[xSol(t), ySol(t)] = dsolve(odes);


xSol(t) = simplify(xSol(t));
ySol(t) = simplify(ySol(t));
General_Solution=[xSol(t) ; ySol(t)]

General_Solution =

if Eigen_Values<0 then
display('The system is stable')
else
display('The system is unstable')
end

The system is unstable

syms x(t) y(t) z(t)


A = input('Coefficient Matrix:');
[V, D]=eig(A);
Eigen_Values=diag(D);
Y = [x; y; z];
odes = diff(Y) == A*Y

odes(t) =

6
[xSol(t), ySol(t), zSol(t)] = dsolve(odes);
xSol(t) = simplify(xSol(t));
ySol(t) = simplify(ySol(t));
zSol(t) = simplify(zSol(t));
General_Solution=[xSol(t); ySol(t); zSol(t)]

General_Solution =

if Eigen_Values<0 then
display('The system is stable')
else
display('The system is unstable')

The syatem is unstable

end

Solve �=� (constant coefficient)

syms y(x)
equation=input('Enter the equation');
sol=dsolve(equation);
Solution=simplify(sol)

Solution =

Solve �′′+��′−��=�.

syms y(x)
equation=input('Enter the equation');
sol=dsolve(equation);
Solution=simplify(sol)

Solution =

Solve the initial value problem: (��−�−�+�)�=�; �(�)=�, �′(�)=�, �′′(�)=�

% Define the differential equation


% Use the symbolic toolbox
syms y(t)
Dy = diff(y, t);
D2y = diff(y, t, 2);

7
D3y = diff(y, t, 3);
% Define the differential equation
ode = D3y - D2y - 4*Dy + 4*y == 0;
% Define the initial conditions
conds = [y(0) == 1, subs(Dy, t, 0) == 2, subs(D2y, t, 0) == 1];
% Solve the ODE with the initial conditions
sol = dsolve(ode, conds);
% Display the solution
disp('The solution to the initial value problem is:');

The solution to the initial value problem is:

Solve �′′′−��′′+��′−��=�..

syms y(x)
equation=input('Enter the equation');
sol=dsolve(equation);
Solution=simplify(sol)

Solution =

Solve (��−�+�)�=�..

syms y(x)
equation=input('Enter the equation');
sol=dsolve(equation);
Solution=simplify(sol)

Solution =

Solve (��+�+�)�=�. (Non-Homogeneous equation)

syms y(x)
equation=input('Enter the equation');
sol=dsolve(equation);
Solution=simplify(sol)

Solution =

Solve (��+�)�=�.

syms y(t)
equation=input('Enter the equation');
sol=dsolve(equation);
Solution=simplify(sol)

8
Solution =

Solve (��−�+�)�=�(�)

syms y(x)
equation=input('Enter the equation');
sol=dsolve(equation);
Solution=simplify(sol)

Solution =

Solve (��+�)�=�.

syms y(x)
equation=input('Enter the equation');
sol=dsolve(equation);
Solution=simplify(sol)

Solution =

Solve (��+�)�=�+�+�.

syms y(x)
equation=input('Enter the equation');
sol=dsolve(equation);
Solution=simplify(sol)

Solution =

Solve �′′+��′+�=�+�.

syms y(x)
equation=input('Enter the equation');
sol=dsolve(equation);
Solution=simplify(sol)

Solution =

9
Solve (��−�+�)�=�.

syms y(x)
equation=input('Enter the equation');
sol=dsolve(equation);
Solution=simplify(sol)

Solution =

Solve (��+�−�)�=�.

syms y(x)
equation=input('Enter the equation');
sol=dsolve(equation);
Solution=simplify(sol)

Solution =

Solve (��+�)�=�+� .

syms y(x)
equation=input('Enter the equation');
sol=dsolve(equation);
Solution=simplify(sol)

Solution =

Solve �′′+��=�.

syms y(x)
equation=input('Enter the equation');
sol=dsolve(equation);
Solution=simplify(sol)

Solution =

Solve �′′+��=�.

syms y(x)
equation=input('Enter the equation');

10
sol=dsolve(equation);
Solution=simplify(sol)

Solution =

Solve �′′−��′+��=�.

syms y(x)
equation=input('Enter the equation');
sol=dsolve(equation);
Solution=simplify(sol)

Solution =

Solve �′′−��′+��=�.

syms y(x)
equation=input('Enter the equation');
sol=dsolve(equation);
Solution=simplify(sol)

Solution =

Solve �′′−� �′+�=�. (Equation with variable coefficients-Cauchy’s equation)

syms y(x)
equation=input('Enter the equation');
sol=dsolve(equation);
Solution=simplify(sol)

Solution =

Solve �+�+�=�(�+�). (Cauchy’s equation)

syms y(x)
equation=input('Enter the equation');
sol=dsolve(equation);
Solution=simplify(sol)

Solution =

Solve �′′−��′+��=(�+�)�. (Cauchy’s equation)

11
syms y(x)
equation=input('Enter the equation');
sol=dsolve(equation);
Solution=simplify(sol)

Solution =

Solve �′′+��′+��=�+� (��). (Cauchy’s equation)

syms y(x)
equation=input('Enter the equation');
sol=dsolve(equation);
Solution=simplify(sol)

Solution =

Solve (��−�)� �+(��−�)�−�=�−�+�. (Legendre’s equation)

syms y(x)
equation=input('Enter the equation');
sol=dsolve(equation);
Solution=simplify(sol)

Solution =

Solve (��+�)� �−�(�+�) �+�=�(�+�)�. (Legendre’s equation)

syms y(x)
equation=input('Enter the equation');
sol=dsolve(equation);
Solution=simplify(sol)

Solution =

Exercise Problems:

1. Obtain the solution for �2�2+4�=0, given that �=2 and �=0 when x=0 using MATLAB code.

12
% Define the symbolic variables
syms y(x)
% Define the differential equation
eqn = diff(y, x, 2) + 4*y == 0;
% Define the initial conditions
Dy = diff(y, x);
cond1 = y(0) == 2;
cond2 = Dy(0) == 0;
% Solve the differential equation with the initial conditions
sol = dsolve(eqn, cond1, cond2);
% Display the solution
disp(sol);

2. Obtain the solution for (�4−6�3+12�2−8�)�=0 using MATLAB code.

% Define the symbolic variable


syms y(x)
% Define the differential operator D as the derivative with respect to x
D = diff(y, x);
% Define the differential equation
eqn = diff(y, x, 4) - 6*diff(y, x, 3) + 12*diff(y, x, 2) - 8*diff(y, x) == 0;
% Solve the differential equation
sol = dsolve(eqn);
% Display the solution
disp(sol);

3. Obtain the solution for (D3+8)�=�4+2�+1 using MATLAB code.

% Define the symbolic variable


syms y(x) x
% Define the differential equation
eqn = diff(y, x, 3) + 8*y == x^4 + 2*x + 1;
% Solve the differential equation
sol = dsolve(eqn);
% Display the solution
disp(sol);

4. Obtain the solution for (D2−2D+2)�=sin� using MATLAB code.

% Define the symbolic variable


syms y(x)

13
% Define the differential equation
eqn = diff(y, x, 2) - 2*diff(y, x) + 2*y == sin(x);
% Solve the differential equation
sol = dsolve(eqn);
% Display the solution
disp(sol);

5. Obtain the solution for (�3−7�−6)�=(1+�)�2� using MATLAB code.

% Define the symbolic variables


syms y(x)
% Define the differential equation
eqn = diff(y, x, 3) - 7*diff(y, x) - 6*y == (1 + x)*exp(2*x);
% Solve the differential equation
sol = dsolve(eqn);
% Display the solution
disp(sol);

6. Obtain the solution for �′′+�=�sin� using MATLAB code.

% Define the symbolic variable


syms y(x)
% Define the differential equation
eqn = diff(y, x, 2) + y == x*sin(x);
% Solve the differential equation
sol = dsolve(eqn);
% Display the solution
disp(sol);

7. Obtain the solution for �′′−2�′+�=� using MATLAB code.

% Define the symbolic variable


syms y(x)
% Define the differential equation
eqn = diff(y, x, 2) - 2*diff(y, x) + y == exp(x)/x;
% Solve the differential equation
sol = dsolve(eqn);
% Display the solution

14
disp(sol);

8. Obtain the solution for �2�′′−2��′−4�=�4 using MATLAB code.

% Define the symbolic variable


syms y(x)
% Define the differential equation
eqn = x^2*diff(y, x, 2) - 2*x*diff(y, x) - 4*y == x^4;
% Solve the differential equation
sol = dsolve(eqn);
% Display the solution
disp(sol);

9. Obtain the solution for �2 �2�2−3��+4�=(1+�)2 using MATLAB code.

% Define the symbolic variable


syms y(x)
% Define the differential equation
eqn = x^2*diff(y, x, 2) - 3*x*diff(y, x) + 4*y == (1 + x)^2;
% Solve the differential equation
sol = dsolve(eqn);
% Display the solution
disp(sol);

10. Obtain the solution for (2�+1)2 �2�2−2(2�+1)��−12�=6�+5 using MATLAB code.

% Define the symbolic variable


syms y(x)
% Define the differential equation
eqn = (2*x + 1)^2*diff(y, x, 2) - 2*(2*x + 1)*diff(y, x) - 12*y == 6*x + 5;
% Solve the differential equation
sol = dsolve(eqn);
% Display the solution
disp(sol);

15
16

You might also like