summaryrefslogtreecommitdiff
path: root/3588/CH5/EX5.2/EX5_2.sce
blob: 1c31c63cf6f1911790f6ca331e858d10009de6cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//Clearing console
clc
clear

x = poly(0,"x")

//Intializing variables
x0 = 0
x1 = 1

//Consrtucting K and F matrices to solve the residual equations
K(1,1:2) = [integrate('x*(x-1)*2','x',x0,x1) integrate('x*(x-1)*2*(3*x-1)','x',x0,x1)]
K(2,1:2) = [integrate('x^2*(x-1)*2','x',x0,x1) integrate('x^2*(x-1)*2*(3*x-1)','x',x0,x1)]

F = [integrate('x*(x-1)*(10*(x^2)+5)','x',x0,x1); integrate('x^2*(x-1)*(10*(x^2)+5)','x',x0,x1)]

//Solving for constants in assumed solution
U(1:2,1)=linsolve(K,-F)

S = U(1,1)*x*(x-1)+U(2,1)*x^2*(x-1)

//Calculating solution for given differntial equation
for t =1:11
    P(1,t) = (U(1,1)*(t-1)*(t-11)/100)+(U(2,1)*(t-1)^2*(t-11)/1000)
end

//Constructing x matrix
k = 0:0.1:1;

//plotting solution
plot(k,P);
xtitle('solution','x','y(x)')

printf('\nResults\n')
printf('\nSolution of the Differential Equation y(x) =') 
disp(S)