Docsity
Docsity

Prepara tus exámenes
Prepara tus exámenes

Prepara tus exámenes y mejora tus resultados gracias a la gran cantidad de recursos disponibles en Docsity


Consigue puntos base para descargar
Consigue puntos base para descargar

Gana puntos ayudando a otros estudiantes o consíguelos activando un Plan Premium


Orientación Universidad
Orientación Universidad


Qüestionari 2 Matlab CNED, Ejercicios de Cálculo

Qüestionari 2 de Càlcul numèric i equacions diferencial de MATLAB

Tipo: Ejercicios

2020/2021
En oferta
30 Puntos
Discount

Oferta a tiempo limitado


Subido el 17/03/2021

violant-perez
violant-perez 🇪🇸

4.9

(10)

10 documentos

1 / 24

Toggle sidebar

Esta página no es visible en la vista previa

¡No te pierdas las partes importantes!

bg1
MATLAB Q2
Pregunta 1
Command Window
>> clear all
>> format long
>> xpb = [-1,0,3];
>> ypb = [-16,-4,-28];
>> npb = length(xpb);
>> figure(5); clf;
>> plot(xpb,ypb,'bo')
>> legend('punts base','Location','NorthWest');
>> a = polyfit(xpb,ypb,npb-1)
a =
Columns 1 through 2
-4.999999999999996 6.999999999999993
Column 3
-4.000000000000002
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
Discount

En oferta

Vista previa parcial del texto

¡Descarga Qüestionari 2 Matlab CNED y más Ejercicios en PDF de Cálculo solo en Docsity!

MATLAB Q

Pregunta 1 Command Window

clear all format long xpb = [-1,0,3]; ypb = [-16,-4,-28]; npb = length(xpb); figure(5); clf; plot(xpb,ypb,'bo') legend('punts base','Location','NorthWest'); a = polyfit(xpb,ypb,npb-1) a = Columns 1 through 2

  • 4.999999999999996 6. Column 3

Pregunta 2 Command Window format long

f =@(x) x.sin(-2x)-6; xpb =[-16:4:16]; ypb = f(xpb); punts = [-12.4,4.36]; imatges = interp1(xpb,ypb,punts,'linear') imatges = 2.897963619684830 - 9. Pregunta 3

1.805399285714286e+ Pregunta 4 Command Window

format long xpb = [-20,-16,-12,-8,-4,0,4,8,12,16,20]; ypb = [0,442368,245760,0,-73728,0,73728,0,-245760,-442368,0]; npb = length(xpb); figure(5); clf; plot(xpb,ypb,'bo') legend('punts base','Location','NorthWest'); a = polyfit(xpb,ypb,5) a(end) a(1) a(2) a(end-1)

ans = 2.560000000000001e+

polyval( a, 24) ans = 2.162687999999998e+ Pregunta 5 Command Window format long xpb = [0:0.01:1]; ypb = ceil(10(3sin(5xpb)+4cos(3xpb)+3exp(-2*xpb)))/10; plot(xpb,ypb,'o')

punts = part; n=length(punts)-1; % h = (b-a)/n; % punts = [a:h:b]; IT=0; for i=1:n %%%% com que els intervals no són equiespaiats %%%% la h s'ha de calcular per cada interval % interval [xi , xi1] xi=punts(i); % punt esquerra xi1=punts(i+1); % punt de la dreta hi = xi1-xi; IT=IT + ( f(xi) + f(xi1) )/2 * hi; end end Command Window Clear all clc format long

f =@(x) (1/100000)x^2+(1/1000000)x+(7/1000000); a=-5; b=69; n=74; h = (b-a)/n; part = [a:h:b]; [IT] = MetodeTrapeziGeneral(f,part) Pregunta 7

Funció function [IT] = MetodeTrapeziGeneral(f,part) punts = part; n=length(punts)-1; % h = (b-a)/n; % punts = [a:h:b]; IT=0; for i=1:n %%%% com que els intervals no s√≥n equiespaiats %%%% la h s'ha de calcular per cada interval % interval [xi , xi1] xi=punts(i); % punt esquerra xi1=punts(i+1); % punt de la dreta hi = xi1-xi; IT=IT + ( f(xi) + f(xi1) )/2 * hi; end end Command Window Clear all clc format long;

f = @(x) (-1/1250)x^2-(1/2000)x+(1/1250); a = 10; b = 25;

ninicial=3; nfinal=6; k = nfinal/ninicial k = 2 q=4; pred_E_IS_n9 = E_IS_n3 / 2^ pred_E_IS_n9 = 9.786858668600629e- 05 Pregunta 9

Command Window Clear all clc format long

f =@(x) - cos(-45*x)+x; a = - 6; b = - 5; syms z; Iexa = double(int(f(z),a,b)) n=2; h= (b-a)/n; punts= [a:h:b]; sol_integral = integral(f,a,b) [IS] = MetodeSimpson(f,a,b,n) [IT] = MetodeTrapezi(f,a,b,n) E_IS_exacte = abs(Iexa - IS) E_IT_exacte = abs(Iexa - IT) E_IS_predic4 = E_IS_exacte / 2^ E_IT_predic4 = E_IT_exacte / 2^ E_IS_predic8 = E_IS_exacte / 4^ E_IT_predic8 = E_IT_exacte / 4^

Command Window

format long f =@(x) 3/500x^3+3/500x^2+1/200*x+3/500; a=8; b=39/4; n=7; [ISQ] = MetodeSimpsonQuart(f,a,b,n) ISQ =

Pregunta 11

Funció function [IRQM] = MetodeRectangeQuartModificat(f,a,b,n) h = (b-a)/n; punts = [a:h:b]; IRQM=0; for i=1:n xi=punts(i); xi1=punts(i+1); xq = xi + h/4; IRQM = IRQM+h*f(xq); end Command Window

format long f=@(x)(-1/1250000)x^3-(7/10000000)x^2-(1/1000000)*x- (9/10000000); a=3; b=105/2; n=99; [IRQM] = MetodeRectangeQuartModificat(f,a,b,n) Pregunta 12

Pregunta 13 Funció function [Y]=Euler(f,a,b,alpha,n) h = (b-a)/n; t=[a:h:b]; Y(1) = alpha; for i = 1:n Y(i+1) = Y(i) + h * f( t(i) , Y(i) ); end

Command Window format long

f= @(t,y)-2t-5t*y; a=0; alpha=0; b=1; n=7; [Y]=Euler(f,a,b,alpha,n) Y = Columns 1 through 2 0 0 Columns 3 through 4

  • 0.040816326530612 - 0. Columns 5 through 6
  • 0.201633673044395 - 0. Columns 7 through 8
  • 0.342497724464348 - 0.

Y(end) ans =

h = (b-a)/n; t = [a:h:b]; [t;Y] ans =

prediccio = errorGlobal / 2 prediccio =

Pregunta 14 Funció function [Y]=RK4(f,a,b,alpha,n) h = (b-a)/n; t=[a:h:b]; Y(1) = alpha; for i = 1:n k1=f(t(i), Y(i)); k2=f(t(i)+h/2, Y(i)+k1/2h); k3=f(t(i)+h/2, Y(i)+k2/2h); k4=f(t(i)+h, Y(i)+k3h); Y(i+1) = Y(i)+h/6(k1+2k2+2k3+k4); end

Command Window format long

f= @(t,y) 2t-9t*y; a=0; alpha=0; b=1; n=5; [Y]=RK4(f,a,b,alpha,n) Y = Columns 1 through 2 0 0. Columns 3 through 4 0.114068496532480 0. Columns 5 through 6 0.208782244581366 0. Y(end) ans =

h=(b-a)/n; t=[a:h:b]; yexa=-((2exp(-(9t.^2)/2))/9)+2/9; error=yexa-Y; errorGlobal=yexa(end)-Y(end) errorGlobal =