The coding below gives me a final answer of 128, however I need a value around 124. Please help.

1 次查看(过去 30 天)
The data for the code below is:
Time (seconds) (t)
21.6
24
25.8
28.2
30
31.8
34.2
36
37.8
40.2
42
43.8
46.2
48
49.8
52.2
54
55.8
58.2
60
61.8
64.2
66
67.8
70.2
72
73.8
76.2
78
79.8
82.2
84
85.8
88.2
90
91.8
94.2
96
97.8
100.2
102
103.8
106.2
DOT (%)
10.7590349
12.33302268
13.71026199
15.63632598
17.14818267
18.59790825
19.99585793
21.27990059
22.83317801
24.50036243
26.0225743
27.94863829
29.84363674
31.4279797
32.77415346
34.15139277
35.63218391
37.05084395
38.61447655
39.97100549
41.67961065
43.15684995
44.14414414
45.69742156
46.88826758
48.29657243
50.17086052
51.24779952
52.78036657
54.02298851
55.22418971
56.63249456
57.76120949
58.98312105
60.07041524
61.30268199
62.65921094
63.96396396
64.80273377
65.69327949
66.67702185
67.62969866
68.4477581
The code is as given below
x(1)=2;
x(2)=3;
error = 0.0001;
for i=3:43
f=@(x) (1./(x-60)).*(x.*exp(-t(i)./x)-60.*exp(-t(i)/60)) - ((100-DOT(i))./100);
x(i) = x(i-1) - (f(x(i-1)))*((x(i-1) - x(i-2))/(f(x(i-1)) - f(x(i-2))));
disp (x(i))
if abs(f(x(i)))< error
break
end
end
tm = (x(i));
disp('This is tm')
disp(tm)
kLa = (1/tm);
disp('kLa = 1/tm')
disp(kLa)
KLAh = (kLa.*3600);
disp('kLa per hour is')
disp(KLAh)
KLAh is supposed to be around 124. Please help.
  3 个评论
Abhishek Jani
Abhishek Jani 2015-3-11
It's a secant method and hence only the last value is used because once it falls below the error value, it terminates, hence converging.
Roger Stafford
Roger Stafford 2015-3-11
In the secant method, as with many other solver algorithms, any parameters that enter into the equation to be solved should always be held constant while attaining convergence. In your code the 't' and 'DOT' variables are acting as parameters, but you are varying them throughout your iteration. If you do manage to get
abs(f(x(i)))< error
at some point in this procedure it will be a solution that corresponds to the particular values of 't' and 'DOT' at that point, and you have no reason to suppose that this will be the value 1.24. It depends on where your procedure happens to break.
You apparently have a misunderstanding of the secant method. You had better do a more careful study of it. See:
http://en.wikipedia.org/wiki/Secant_method

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Financial Toolbox 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by