Numerical Assignment
Numerical Assignment
EKC 245
AHLI KUMPULAN
NAMA
EKMAL HARRIS B ABDUL MALEK
NO.MATRI
K
115836
117893
115841
117890
TAJUK SOALAN
:
NAMA PENSYARAH
:
TARIKH HANTAR PROJEK
:
NUMERICAL METHOD
DR TYE CHIN THIAN
26 MEI 2014
example 25.14
Please input the function:10*exp(-(x-2)^2/(2*0.075^2))-0.6*y
Please input the step size:0.1
Please input the x0:0
Please input the y0:0.5
Please input the xn:4
ans =
0.6125
1.8
1.6
1.4
1.2
1
0.8
0.6
0.4
0.2
0
10
15
20
25
30
35
40
=','s');
% step size
% User input value of x
% Higher Interval of graph
% Calculates upto y(a)
%initial condition
for i=1:(length(x)-1)
% calculation loop
k_1 = cute_cat(x(i),y(i));
k_2 = cute_cat(x(i)+0.5*h,y(i)+0.5*h*k_1);
k_3 = cute_cat((x(i)+0.5*h),(y(i)+0.5*h*k_2));
k_4 = cute_cat((x(i)+h),(y(i)+k_3*h));
y(i+1) = y(i) + (1/6)*(k_1+2*k_2+2*k_3+k_4)*h; % main equation
end
y
disp('Ur value of y would be y = ')
y((abs(c)+a)/h+1)
plot(x,y,a,y((abs(c)+a)/h+1),'*')
%Answer for x
Example 25.14
Ur equation in x and y only yaa dy/dx =10*exp(-(x-2)^2/(2*0.075^2))-0.6*y
meow =
10*exp(-(x-2)^2/(2*0.075^2))-0.6*y
the eq is in form of general dy/dx= meow
Step Size = 0.05
Maximum x = 4
initial x0= 0
Initial condition y(x0) = 0.5
y=
Columns 1 through 9
0.5000
0.3933
0.4852
0.4709
0.4570
0.4435
0.4304
0.4176
0.4053
0.3488
0.3385
0.3285
0.3188
0.3094
0.2663
0.2584
0.2508
0.2434
0.2362
0.2033
0.1973
0.1914
0.1858
0.1804
0.6173
1.0578
1.4847
1.7390
1.8140
1.5988
1.5515
1.5057
1.4612
1.4180
Columns 10 through 18
0.3817
0.3002
0.3704
0.3595
Columns 19 through 27
0.2914
0.2292
0.2828
0.2744
Columns 28 through 36
0.2224
0.1758
0.2159
0.2095
Columns 37 through 45
0.1769
1.7953
0.2069
0.3278
Columns 46 through 54
1.7485
1.3761
1.6976
1.6475
Columns 55 through 63
1.3354
1.0505
1.2960
1.2577
1.2205
1.1844
1.1494
1.1154
1.0825
0.9317
0.9042
0.8774
0.8515
0.8263
0.7112
0.6902
0.6698
0.6500
0.6308
0.5429
0.5269
0.5113
0.4962
0.4815
0.4145
0.4022
0.3903
0.3788
0.3676
0.3164
0.3070
0.2980
0.2892
0.2806
0.2415
0.2344
0.2275
0.2207
0.2142
Columns 64 through 72
1.0194
0.8019
0.9893
0.9601
Columns 73 through 81
0.7782
0.6122
0.7552
0.7329
Columns 82 through 90
0.5941
0.4673
0.5765
0.5595
Columns 91 through 99
0.4535
0.3567
0.4401
0.4271
0.3360
0.3260
0.2565
0.2489
0.1958
0.1900
Ur value of y would be y =
ans =
0.6122
0.1844
2
1.8
1.6
1.4
1.2
1
0.8
0.6
0.4
0.2
0
y_scale=abs(yi(i))+abs(h*k1full);
delta_new=0.1*epsilon*y_scale;
if delta_new >= delta_present
h=h*abs(delta_new/delta_present)^0.2;
else
h=h*abs(delta_new/delta_present)^0.25;
end
if xi(i)+h>=xf
h=xf-xi(i);
end
k1=subs(ydot,{x,y},[xi(i),yi(i)]);
k2=subs(ydot,{x,y},[xi(i)+1/2*h,yi(i)+1/2*k1*h]);
k3=subs(ydot,{x,y},[xi(i)+1/2*h,yi(i)+1/2*k2*h]);
k4=subs(ydot,{x,y},[xi(i)+h,yi(i)+k3*h]);
yi(i+1)=yi(i)+1/6*h*(k1+2*k2+2*k3+k4);
xi(i+1)=xi(i)+h;
if xi(i+1)>=xf
break
else
continue
end
end
yi
plot(xi,yi,'xk',xi,yi)
Example 25.14
Please input the derivative function=10*exp(-(x-2)^2/(2*0.075^2))-0.6*y
Please input step size=0.05
Please input initial x=0
Please input initial y=0.5
Please input final x=4
Please input tolerance=1
Please input maximum number of change for h=10
2
1.8
1.6
1.4
1.2
1
0.8
0.6
0.4
0.2
0
0.5
1.5
2.5
3.5