summaryrefslogtreecommitdiff
path: root/3685/CH7/EX7.5/Ex7_5.sce
blob: 6e0806e33e05b9ce1cb8e9ebef943c368f2b9220 (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
38
39
40
41
42
43
44
45
46
47
48
clear
clc
T = poly(0,'T'); // T = Tf
Tf_ = 700-2*T; // Tf_ = Tf'
// Bisection method to solve for the polynomial

printf("\n Example 7.5")


function [x] = Temperature(a,b,f)
  N = 100;
  eps = 1e-5;
  if((f(a)*f(b))>0) then
    error('no root possible f(a)*f(b)>0');
    abort;
  end;
  if(abs(f(a))<eps) then
    error('solution at a');
    abort;
  end
  if(abs(f(b))<eps) then
    error('solution at b');
    abort;
  end
  while(N>0)
    c = (a+b)/2
    if(abs(f(c))<eps) then
      x = c ;
      x;
      return;
    end;
    if((f(a)*f(c))<0 ) then
      b = c ;
    else
      a = c ;
    end
    N = N-1;
  end
  error('no convergence');
  abort;
endfunction
deff('[y]=p(T)',['y = 2*T^3-700*T^2+9000000 '])
T = Temperature(100,200,p);

Tf_ = horner(Tf_,T);
printf("\n The final temperature of the body C is %d K",Tf_)
//The answers vary due to round off error