# program liczący miejsce zerowe funkcji metodą bisekcji
epi=0.00005 #dokładność
x1=0 #początek przedziału
x2=10 #koniec przedziału
x=(x1+x2)/2 #wartość średnia
def funk (x):
y=2*x*x+3*x-5 #szukamy miejsca zerowego dla tej funkcji
return y
y=funk (x)
print ('epi=',epi)
print ('x1=',x1)
print ('x2=',x2)
print ('x=',x)
print ('')
while abs(y)>epi:
x=(x1+x2)/2
y=funk (x)
y1=funk (x1)
y2=funk (x2)
print('y1=',y)
print('y=',y1)
print('y2=',y2)
print ('')
if y>0:
z='+'
elif y<0:
z='-'
if y1>0:
z1='+'
elif y1<0:
z1='-'
if z1!=z:
x2=x
else:
x1=x
print ('')
print ('y=',y)
print ('')
print ('f(',x,')=0')
Replies to Untitled
Title |
Name |
Language |
UNIX |
When |
f(x)=0 bisekcja |
Mike C. |
python |
1538767842 |
5 Years ago. |
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}