You are on page 1of 7

<html>

<head>
<meta charset="utf-8">
<title></title>
<script type="text/javascript" src="jquery-1.8.3.js"></script>
<script type="text/javascript" src="estructura.js"></script>
<script type="text/javascript">
function soloLetras(e) {
key = e.keyCode || e.which;
tecla = String.fromCharCode(key).toLowerCase();
letras = "-0123456789.";
especiales = [8, 37, 39, 46];
tecla_especial = false
for(var i in especiales) {
if(key == especiales[i]) {
tecla_especial = true;
break;
}
}
if(letras.indexOf(tecla) == -1 && !tecla_especial)
return false;
}

function biseccin () {
var a = parseFloat($("input:eq(0)").val());
var b = parseFloat($("input:eq(1)").val());
var er = parseFloat($("input:eq(2)").val());
var nv = parseInt($("input:eq(3)").val());
var e ;
var aux = true;
var i = 0;
var m;
var r1 ;
var r2 ;
var r3;
var aux1;
var aux2;
var auxm;
var valor_a;
var valor_b;
var mante;
var alto;
if ($("input:eq(0)").val() == "" || $("input:eq(1)").val() == ""
|| $("input:eq(2)").val() == "" || $("input:eq(3)").val() == "") {
alert("Los campos son obligatorios");
}else{
function Fx (a) {
var r ;
r = Math.exp(a) - (3*Math.pow(a,2))
return r;
}

while(aux==true){
if (i == 0) {
m = (a+b)/2;
r1 = Fx(a);
if (r1 < 0) {
aux1 = "-";
}else{
aux1 = "+";
}
r2 = Fx(b);
if (r2 < 0) {
aux2 = "-";
}else{
aux2 = "+";
}
r3 = Fx(m);
if (r3 < 0) {
auxm = "-";
}else{
auxm = "+";
}
if (aux1 != auxm) {
valor_a = a;
valor_b = m;
}else{
valor_a = m;
valor_b = b;
}
mante = m;
$("#resultado").html("<center><table id=
'tb' border='1' rules='all' cellspacing='0'><tr class='th'><th>It</th><th>a</th>
<th>m</th><th>b</th><th>e</th></tr></table></center>");
$("#tb").append("<tr id='"+i+"' class='t
d'><td>"+i+"</td><td>"+a.toFixed(4)+"</td><td>"+m.toFixed(4)+"</td><td>"+b.toFix
ed(4)+"</td><td>"+"0.0000"+"</td></tr>");
};
if (i > 0) {
a = valor_a;
b = valor_b;
m = (a+b)/2;
r1 = Fx(a);
if (r1 < 0) {
aux1 =
}else{
aux1 =
}
r2 = Fx(b);
if (r2 < 0) {
aux2 =
}else{
aux2 =
}
r3 = Fx(m);
if (r3 < 0) {
auxm =
}else{
auxm =
}

"-";
"+"

"-";
"+";

"-";
"+";

if (aux1 != auxm) {
valor_a = a;
valor_b = m;
}else{
valor_a = m;
valor_b = b;
}
e = Math.abs((m - mante) / m);
mante = m ;
$("#tb").append("<tr id='"+i+"' class='t
d'></tr>");
$("#"+i+"").append("<td>"+i+"</td>");
$("#"+i+"").append("<td>"+a.toFixed(4)+"
</td>");
$("#"+i+"").append("<td>"+m.toFixed(4)+"
</td>");
$("#"+i+"").append("<td>"+b.toFixed(4)+"
</td>");
$("#"+i+"").append("<td>"+e.toFixed(4)+"
</td>");
if (e < er) {
aux = false;
};
};
i++;
if (i > (nv-1)) {
aux = false;
};
}
$("#cont").append("<div id='resul' style='margin-left:40
px; position:absolute; bottom: 20px'></p>");
$("#resul").html("Punto Aproximado : "+m.toFixed(4));
alto = 520 + (i * 18)+18;
$("#cont").css("height",alto);
}
}
function rapshon () {
var x0 = parseFloat($("input:eq(0)").val());
var ce = parseFloat($("input:eq(1)").val());
var mit = parseFloat($("input:eq(2)").val());
var v1;
var v2;
var v3;
var x1;
var e;
var alto;
$("#resultado").css("top",445);
function Fxr (x) {
var r ;
r = (2*x*Math.cos(2*x)) - (Math.pow(x-2, 2));
return r;
}

function Dfxr (x) {


var r;
r = (2*Math.cos(2*x)) - (4*x*Math.sin(2*x)) - (2*Math.po
w(x-2 , 2));
return r;
}
var aux = true;
var i = 0;
while(aux == true){
if (i == 0) {
v1 = Fxr(x0);
v2 = Dfxr(x0);
v3 = (v1/v2);
x1 = (x0-v3);
e = Math.abs((x1-x0)/x1);
$("#resultado").html("<center><table id='tb' bor
der='1' rules='all' cellspacing='0'><tr class='th'><th>It</th><th>X0</th><th>X1<
/th><th>Er</th></tr></table></center>");
$("#tb").append("<tr id='"+i+"' class='td'></tr>
")
$("#"+i+"").append("<td>"+i+"</td>");
$("#"+i+"").append("<td>"+x0.toFixed(4)+"</td>")
;
$("#"+i+"").append("<td>"+x1.toFixed(4)+"</td>")
;
$("#"+i+"").append("<td>"+e.toFixed(4)+"</td>");
x0 = x1;
}else{
v1 = Fxr(x0);
v2 = Dfxr(x0);
v3 = (v1/v2);
x1 = (x0-v3);
e = Math.abs((x1-x0)/x1);
$("#tb").append("<tr id='"+i+"' class='td'></tr>
");
$("#"+i+"").append("<td>"+i+"</td>");
$("#"+i+"").append("<td>"+x0.toFixed(4)+"</td>")
;
$("#"+i+"").append("<td>"+x1.toFixed(4)+"</td>")
;
$("#"+i+"").append("<td>"+e.toFixed(4)+"</td>");
if (e < ce) {
aux = false;
};
x0 = x1;
}
i++;
if (i > (mit-1)) {
aux = false;
};
}
alto = 490 + (i * 18) + 18;
$("#cont").css("height",alto);
$("#cont").append("<div id='resul' style='margin-left:40px; posi
tion:absolute; bottom: 20px'></p>");
$("#resul").html("Punto Aproximado : "+x1.toFixed(4));
}

function trapecio () {
var x0 = parseInt($("input:eq(0)").val());
var x1 = parseInt($("input:eq(1)").val());
var Nd = parseInt($("input:eq(2)").val());
var vf;
var h ;
var tvf = 0;
function Fxt (x) {
var r;
r = x*Math.exp(Math.pow(x,2));
return r;
}
h = (x1-x0)/Nd;
for (var i = 0; i < Nd; i++) {
vf = (((x0+h)-x0)/2)*(Fxt(x0) + Fxt(x0+h));
tvf = tvf + vf;
x0 = x0+h;
};
$("#cont").append("<div id='resul' style='margin-left:40px; posi
tion:absolute; bottom: 30px'></p>");
$("#resul").html("Valor Aproximado : "+tvf.toFixed(6));
}
function sipsom () {
var x0 = parseInt($("input:eq(0)").val());
var x2 = parseInt($("input:eq(1)").val());
var x1;
var Nd = parseInt($("input:eq(2)").val());
var vf;
var paso;
var h ;
var tvf = 0;
var v1;
var v2;
var v3;
function Fxs (x) {
var r;
r = Math.sin(x)*Math.sqrt(1 + Math.cos(x));
return r;
}
paso = (x2 - x0)/Nd;
for (var i = 0; i < Nd; i++) {
h = ((x0 + paso) - x0)/2;
x1 = (x0 + h);
v1 = Fxs(x0);
v2 = Fxs(x1);
v3 = Fxs(x0+paso);
v4 = ((x0+paso)-x0)/6;
vf = v4*(v1 + 4*v2 + v3);
tvf = tvf + vf;
x0 = x0 + paso;
};

$("#cont").append("<div id='resul' style='margin-left:40px; posi


tion:absolute; bottom: 30px'></p>");
$("#resul").html("Valor Aproximado : "+tvf.toFixed(6));
}
$(document).ready(function() {
$("#resultado").html("");
$("#contenido").html("<table id='tab'><tr><td>In
grese A : </td><td><input type='text' id='x0' name='x1' class='input' onkeypress
='return soloLetras(event)' ></td></tr><tr><td>Ingrese B : </td><td><input type
='text' onkeypress='return soloLetras(event)'name='x1' class='input'></td></tr><
tr><td>Cota de error : </td><td><input type='text' name='er' class='input' onkey
press='return soloLetras(event)'></td></tr><tr><td>Maximo iteracionnes : </td><t
d><input type='text' name='ni' class='input' ></td></tr></table>");
$("#contenido").append("<br>");
$("#contenido").append("<input type='button' cla
ss='btn' value='Evaluar' onClick='biseccin("+0+")'>");
$("#contenido").append("<br>");
$("#contenido").append("<br>");
$("#contenido").append("<hr>");
$("#nom_metodo").html("Metodo Biseccin");
$("#cont").css("height",520);
$("#resul").html("");
});
</script>
</head>
<body>
<div id="cont">
<div id="cab">
<center>
<h2>Calculo Nmerico</h2>
</center>
</div>
<div id="menu">
<span style="font-size:20px;margin-ledt:40px;">Metodo :</span>
<select id="sl1" onChange="selec_meto(this)" style="font-family:Comic Sans MS;wi
dth:180px;height:30px;font-size:15px; top:0px; position:absolute;">
<option value="1">Biseccin</option>
<option value="2">Rapshon</option>
<option value="3">Trapecio</option>
<option value="4">Sipsom 1/3</option>
</select>
</div>
<center>
<div id="nom_metodo">
Nombre del metodo actual
</div>
<div id="contenido">
</div>
</center>
<div id="resultado" >
<table>
<tr>
<td>Esto mostrara el resultado</td>
</tr>

</table>
</div>
<center>
<div style="position:absolute;color: gray;bottom:0px; width:400px; font:
normal 9px lucida grande,tahoma,verdana,arial,sans-serif;">
Junior Vasquez 2012 - 2013
</div>
</center>
</div>
</body>
</html>

You might also like