Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Ejercicio 1
- function r = misraices2(poli)
- a = coeff(poli, 2);
- b = coeff(poli, 1);
- c = coeff(poli, 0);
- if b < 0 then
- r(1) = (2*c) / (-b + sqrt(b^2-4*a*c));
- r(2) = (-b + sqrt(b^2-4*a*c)) / (2*a);
- else
- r(1) = (-b - sqrt(b^2-4*a*c)) / (2*a);
- r(2) = (2*c) / (-b - sqrt(b^2-4*a*c));
- end;
- endfunction
- //Ejercicio 2
- //Justificación en carpeta
- -->0.9222 * 10^4
- ans =
- 9222.
- -->0.9222 * 10^4 + 0
- ans =
- 9222.
- -->0.9222 * 10^4 + 0.9123 * 10^3
- ans =
- 10134.3
- -->0.1013 * 10^4
- ans =
- 1013.
- -->0.1013 * 10^5
- ans =
- 10130.
- -->0.1013 * 10^5 + 0.3244 * 10^3
- ans =
- 10454.4
- -->0.1045 * 10^5
- ans =
- 10450.
- -->0.1045 * 10^5 + 0.2849 * 10^3
- ans =
- 10734.9
- -->resultado1 = 0.1073 * 10^5
- resultado1 =
- 10730.
- -->0.2849 * 10^3 + 0.3244 * 10 ^ 3
- ans =
- 609.3
- -->0.6093 * 10^3
- ans =
- 609.3
- -->0.6093 * 10^3 + 0.9123 * 10^3
- ans =
- 1521.6
- -->0.1522 * 10 ^ 4
- ans =
- 1522.
- -->0.1522 * 10 ^ 4 + 0.9222 * 10 ^ 4
- ans =
- 10744.
- -->resultado2 = 0.1074 * 10^5
- resultado2 =
- 10740
- -->resultadoPosta = 9222 + 912.3 + 324.4 + 284.9
- resultadoPosta =
- 10743.6
- //Ejercicio 3
- //Apartado b
- function r = horny(polinomio, valor)
- grado = length(coeff(polinomio))
- r = coeff(polinomio, grado)
- for i = grado-1:-1:0
- r = r * valor + coeff(polinomio, i)
- end
- endfunction
- //Apartado d
- function r = horny2(polinomio, valor)
- grado = length(coeff(polinomio))
- r(1) = coeff(polinomio, grado)
- r(2) = coeff(polinomio, grado)
- for i = grado-1:-1:1
- r(1) = r(1) * valor + coeff(polinomio, i)
- r(2) = r(2) * valor + r(1)
- end
- r(1) = r(1) * valor + coeff(polinomio, 0)
- endfunction
- //Ejercicio 4
- //La introducción de error viene de un método malo, y se va propagando en cada iteración.
- function y = aplicar(f,var,x)
- deff("z=F("+var+")","z="+f)
- y = F(x)
- endfunction
- function y = derivame(fun, var, orden, step, valor)
- if orden == 0 then
- y = aplicar(fun, var, valor)
- else
- deff("z = Pepe0("+var+")", "z =" + fun)
- for i=1:orden-1
- deff("z = Pepe"+string(i)+"("+var+")", "z = numderivative(Pepe"+string(i-1)+","+var+","+string(step)+",4)")
- end;
- deff("z = Fin("+var+")", "z = numderivative(Pepe"+string(orden-1)+","+var+","+string(step)+",4)")
- y = Fin(valor)
- end;
- endfunction
- function y = MInumderivative(fun, step, valor)
- y = (fun(valor + step) - fun(valor)) / step
- endfunction
- function y = MIderivame(fun, var, orden, step, valor)
- if orden == 0 then
- y = aplicar(fun, var, valor)
- else
- deff("z = Pepe0("+var+")", "z =" + fun)
- for i=1:orden-1
- deff("z = Pepe"+string(i)+"("+var+")", "z = MInumderivative(Pepe"+string(i-1)+","+string(step)+","+var+")")
- end;
- deff("z = Fin("+var+")", "z = MInumderivative(Pepe"+string(orden-1)+","+string(step)+","+var+")")
- y = Fin(valor)
- end;
- endfunction
- //Ejercicio 5
- function y = aplicar(f,var,x)
- deff("z=F("+var+")","z="+f)
- y = F(x)
- endfunction
- function y = derivame(fun, var, orden, step, valor)
- if orden == 0 then
- y = aplicar(fun, var, valor)
- else
- deff("z = Pepe0("+var+")", "z =" + fun)
- for i=1:orden-1
- deff("z = Pepe"+string(i)+"("+var+")", "z = numderivative(Pepe"+string(i-1)+","+var+","+string(step)+",4)")
- end;
- deff("z = Fin("+var+")", "z = numderivative(Pepe"+string(orden-1)+","+var+","+string(step)+",4)")
- y = Fin(valor)
- end;
- endfunction
- function y = factorial (n)
- if n == 0 then
- y = 1
- else
- y = n * factorial (n-1)
- end
- endfunction
- function y = taylor(fun, var, inicio, grado, valor)
- deff("z = Funcion("+var+")", "z =" + fun)
- y = Funcion(inicio)
- for i=1:grado
- y = y + (derivame(fun, var, i, 0.01, inicio) * (valor - inicio)**i / factorial(i))
- end
- endfunction
- // Ejercicio 6
- function y = ejercicio6(valor, grado)
- y = 1
- for i = 1:grado
- y = y + valor**i / factorial(i)
- end
- endfunction
- --> ejercicio6(-2,10)
- ans =
- 0.1353792
- --> %e**-2
- ans =
- 0.1353353
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement