0% found this document useful (0 votes)
5 views4 pages

Unit2 Lauc-A

This document outlines a MATLAB assignment focused on differential calculus, covering topics such as limits, Taylor's and Maclaurin's theorem, successive differentiation, and solving differential equations. It includes interactive programming elements for user input and provides examples for various mathematical operations. Additionally, it addresses applications in heat flow and electric circuits, demonstrating how to generate and solve differential equations in MATLAB.
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)
5 views4 pages

Unit2 Lauc-A

This document outlines a MATLAB assignment focused on differential calculus, covering topics such as limits, Taylor's and Maclaurin's theorem, successive differentiation, and solving differential equations. It includes interactive programming elements for user input and provides examples for various mathematical operations. Additionally, it addresses applications in heat flow and electric circuits, demonstrating how to generate and solve differential equations in MATLAB.
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/ 4

%date: 12/12/24

%Unit-II DIFFERENTIAL CALCULUS MATLAB Assignment


%124B1G084:Atharv Patil

%Limit/indeterminate form
syms x % Symbolic Variable
limit(cos(x), x, pi/2) % input angle consider in radian
limit(sind(x), x, 90) % Input angle consider in degree
% Interactive Programming
g=input("Enter the function g(x): ");
a=input("Enter the value 'a' for which limit x tends to 'a': "); h=limit(g,
x, a);
fprintf("The limit of the function g(x)=%s at x tends to %d is %s", g, a, h)

%Taylor's and Maclaurin's theorem


taylor(exp(x), x, a=2) % If a=0 the it gives Maclaurin's expansion
taylor(exp(x), x, 0) % Maclaurin's series
% By deafulttaylor() expand series up to degree 5
taylor(exp(x), x, 0, Order=10) % Expand function up to degree 9. % If
Order=n then we get expansion up to degree n-1
%sympref("PolynomialDisplayStyle","ascend") % expand series in ascending
powers
%sympref("PolynomialDisplayStyle","descend") % expand series in descending
powers
%sympref("PolynomialDisplayStyle","default") % expand series in deafult
setting
% Expansion of function of more than one variable
syms x y z
taylor(sin(y)+cos(z), y, 0) % expand in powers of y
taylor(sin(y)+cos(z), z, 0) % expand in powers of y
taylor(sin(y)+cos(z), [y, z], 0) % expand in both powers of x & y
% Interactive Programming
f=input("Enter the function f(x): ")
a=input("Expansion at point a: ") % expansion in powers of (x-a)
b=input("Order of the expansion is b: ")
g=taylor(f, x, a, Order=b);
fprintf("The expansion of f(x)=%s at x=%i is \n %s", f, a, g)

% Successive Differentiation
symsx y % Symbolic variable
diff(x^3-2*x, x, 2) % differentiate function x^3-2*x 2 times w.r.t.
x diff(x^2*y-3*x*y^3, x, 1) % First Order partial derivative w.r.t. x
diff(x^2*y-3*x*y^3, y, 2) % Second Order partial derivative w.r.t. y
% Interactive Programming
f=input("Enter the function f(x)=")
n=input("Enter order of the derivative n=")
for i=1:n
f_d=diff(f, x, i);

1
fprintf("The %i derivative of the function f(x) is %s \n", i, f_d);
end

% Successive Differentiation Using Partial Fraction


syms x
f=input('Enter your function f(x): ')
% Perform partial fraction decomposition
f_pf=partfrac(f)
fprintf('The partial fraction of the function f(x) is %s', f_pf)
n=input('Enter the required order of derivative n: ')
for i=1:n
f_d=diff(f_pf, x, i)
fprintf('The %i derivative of the function f(x) is %s', i, f_d)
end

% Exact &Non Exact Differential Equation


symsx y C
% Define M(x, y) and N(x, y)
M = input('Enter M(x, y): ')
N = input('Enter N(x, y): ')
% Check for exactness
dM_dy = diff(M, y)
dN_dx = diff(N, x)
if dM_dy~=dN_dx
disp('Given differential equation is non excat')
IF=input('Enter integrating factor mu(x, y): ')
M = M * IF
N = N * IF
M_intx = int(M, x) % Integrate M w.r.t. x
N_inty = int(N - diff(M_intx, y), y); % Integrate remaining terms w.r.t. y
GS = M_intx + N_inty;
fprintf('The general solution(GS) is %s ==C', GS)
else
disp('Given differential equation is exact')
M_intx = int(M, x); % Integrate M w.r.t. x
N_inty = int(N - diff(M_intx, y), y); % Integrate remaining terms w.r.t. y
GS = M_intx + N_inty;
fprintf('The general solution(GS) is %s ==C', GS)
end
OR
% 11) Exact & Non Exact Differential Equation
syms x y c
disp("Given functions are")
M=input("Enter the function M(x,y)")
N=input("Enter the function N(x,y)")
disp("First order partial derivatives are")
My=diff(M,y)
Nx=diff(N,x)
if My==Nx

2
disp("Since, My=Nx, given D.E. is Exact")
terms = sym(children(expand(N)));
terms_free_from_x = sum(terms(~has(terms, x)));
sol=int(M,x)+int(terms_free_from_x,y)==c
else
disp("Since, My=!Nx, given D.E. is Non-Exact")
IF=input("Enter Integrating factor to convert it in to exact")
M1=expand(M*IF);
N1=expand(N*IF);
terms = sym(children(N1));
terms_free_from_x = sum(terms(~has(terms, x))); sol=int(M1,x)
+int(terms_free_from_x,y)==c
end

% Heat Flow
syms T(x) x
x1=input('Enter the inner radius of the pipe (x1): ')
x2=input('Enter the outer radius of the pipe (x2): ')
T1=input('Enter the inner temperature of the pipe (T1): ')
T2=input('Enter the inner temperature of the pipe (T2): ')
k=input('Enter coefficient of thermal conductivity: ')
% find q heat flux/loss first
q= -2*pi*k*(T2-T1)/(log(x2/x1))
% Display the heat flux
fprintf('Heat flux q = %s', q);
a=input('Enter distance normal to the surface area(a): ')
Temp=(T2 - T1) / log(x2 / x1) * log(a / x1) + T1

% Solving Homogeneous LDE


syms x y(x)
ode= diff(y,x,2)+5*diff(y,x)+6*y==0
sol=dsolve(ode);
expand(sol)
% Interactive Programming
syms x y(x)
ode=input("Enter Differential equation")
sol=dsolve(ode);
expand(sol)

% Solving Non-homogeneous LDE


syms x y(x)
ode= diff(y,x,2)+3*diff(y,x)+2*y==exp(exp(x))
sol=dsolve(ode);
expand(sol)
% Interactive Programming
syms x y(x)
ode=input("Enter Differential equation")

3
sol=dsolve(ode);
expand(sol)

% Application on Electric Circuit


Step I: Generate differential equation from given electric circuit
%��2�� ����2 + 3���� ����+ 2�� = sin(��)

Step II: solve using previous code of higher order LDE; syms t q(t)
ode= diff(q,t,2)+3*diff(q,t)+2*q==sin(t)
sol=dsolve(ode);
expand(sol)

You might also like