Engineering Analysis and Design
Engineering Analysis and Design
Code :
%Function Name
function [] = HomoPDE()
syms D d x y z m f1 f2 f3
%D is wrt x and d is wrt y
%We take f1, f2 and f3 inplace of phi1, phi2 and phi3
%F is LHS and f is RHS
F = (D*D*D - 6*D*D*d + 11*D*d*d - 6*d*d*d)*z;
f = exp(5*x + 6*y);
%Substitute D with m and d with 1
eqn1 = subs(F, D, m);
eqn2 = subs(eqn1, d, 1)
Results:
>> HomoPDE
eqn2 =
z*(m^3 - 6*m^2 + 11*m - 6)
mval =
1
2
3
CF =
valx =
valy =
2K22/MC/60
PI =
-exp(5*x + 6*y)/91
final_ans =
>>
Code I:
%Function Name
function [] = HomoPDE_cos()
syms D d f1 f2 f3 y x z m c
%D is wrt x and d is wrt y
%We take f1 and f2 inplace of phi1 and phi2
%F is LHS and f is RHS
F = (D*D - 3*D*d + 2*d*d)*z;
f = 2*cos(x+3*y);
mval =
1
2
CF =
f1*(x + y) + f2*(2*x + y)
fn =
cos(x + 3*y)
eqnx =
eqny =
3.0000
PI_deno =
-10
PI =
-cos(x + 3*y)/5
final_ans =
>>
Code II:
%Function Name
function [] = HomoPDE_sin()
syms D d f1 f2 f3 y x z m c
2K22/MC/60
%D is wrt x and d is wrt y
%We take f1 and f2 inplace of phi1 and phi2
%F is LHS and f is RHS
F = (D*D - 5*D*d + 4*d*d)*z;
f = sin(2*x+3*y);
Results:
>> HomoPDE_sin
mval =
1
4
CF =
f1*(x + y) + f2*(4*x + y)
eqnx =
2K22/MC/60
eqny =
3
PI_deno =
-10
PI =
-sin(2*x + 3*y)/10
final_ans =
>>
Code :
%Function Name
function [] = HomoPDEgen_sol()
%t is any random variable
syms D d f1(t) f2(t) f3(t) y x z m c
%D is wrt x and d is wrt y
%We take f1, f2 and f3 inplace of phi_1, phi_2 and phi_3
%F is LHS and f is RHS
F = (D*D*D + 2*D*D*d - D*d*d- 2*d*d*d)*z;
f = (y+2)*exp(x);
Results:
>> HomoPDEgen_sol
mval =
-2
-1
1
CF =
2K22/MC/60
PI =
y*exp(x)
final_ans =
2K22/MC/60
PROGRAM-7
Write a program to solve heat equation u_t(x,t) = c^2*u_xx(x,t) subject
to boundary conditions and the initial conditions.
Theory:
Let u(x,t) denote the temperature at point x at time t. The equation governing this setup is the so-called one-
dimensional heat equation: u_t(x,t) = c^2*u_xx(x,t), where k>0 is a constant (the thermal conductivity of the
material).
Boundary Conditions:
u(0,t) = u(a,t) = 0 for all t
Initial Condition:
u(x,0) = f(x)
0<x<a , t>0
Code :
sturm_liouville.m
function [e_value, e_function] = sturm_liouville(L)
syms y(x)
syms lambda n
%Equation is, y" + (lambda)y = 0
L = 1;
%L = pi/4;
Heat_eqn.m
syms x T B Bn C C1 C2 Ux lambda
%INCLUDE FUNCTION
%e_value is the p term which is equal to root(lambda)
[e_value, e_function] = sturm_liouville()
e_value = sqrt(e_value);
%SOLUTION
sol1 = subs(e_function,lambda,e_value)
%we can also use dsolve for this
sol = int(1/T,T)==int(-e_value*e_value*k,t);
sol2 = C*solve(sol,T)
sol1 = subs(sol1,C1,0)
Ux = sol1*sol2;
Ux = subs(Ux,-C*C2,Bn)
%Bn is half range fourier sine series
Results:
>> Heat_eqn
ans =
'Solving for various conditions...'
ans =
e_function =
2K22/MC/60
C1*cos(lambda^(1/2)*x) - C2*sin(lambda^(1/2)*x)
ans =
ans =
ans =
ans =
n^2*pi^2
e_function =
C1*cos(lambda^(1/2)*x) - C2*sin(lambda^(1/2)*x)
sol1 =
C1*cos(x*(pi*(n^2)^(1/2))^(1/2)) - C2*sin(x*(pi*(n^2)^(1/2))^(1/2))
Warning: Solutions are only valid under certain conditions. To include parameters
and conditions in the solution, specify the 'ReturnConditions' value as 'true'.
> In sym/solve>warnIfParams (line 478)
In sym/solve (line 357)
In Heat_eqn (line 13)
sol2 =
2K22/MC/60
C*exp(-k*n^2*t*pi^2)
sol1 =
-C2*sin(x*(pi*(n^2)^(1/2))^(1/2))
Ux =
Bn*exp(-k*n^2*t*pi^2)*sin(x*(pi*(n^2)^(1/2))^(1/2))
>>
2K22/MC/60