Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
# Bisection (numerical method) - Método da Bissecção
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
# Bisection (numerical method) - Método da Bissecção #….......................................... # Inserir sua função abaixo: g <- function(x){ x^3 - 6*x^2 - 33*x + 76 } #............................................ bis <- function(f,a,b,tol){ if( f(a)*f(b) > 0){ warning("Não existem raízes no intervalo: [",a,",",b,"]") }else{ while( (b-a)/2 > tol){ fa = f(a) fb = f(b) pm = (a+b)/2 fpm = f(pm) if( fpm*fb < 0){ a <- pm }else{ b <- pm pm <- (a+b)/2 } } } cat("Raíz: ", pm) curve(f, pm - 10, pm + 10) abline(h=0,v=0) points(pm,0, pch = 19, col = 'red') } bis(g,-5,1,0.00001) cat("\n ") bis(g,0,3,0.00001) cat("\n") bis(g,5,10,0.00001)
[
+
]
Show input
Absolute running time: 0.68 sec, cpu time: 0.61 sec, memory peak: 32 Mb, absolute service time: 0,7 sec
edit mode
|
history
|
discussion
Raíz: -4.640512 Raíz: 1.866611 Raíz: 8.773899