View
10
Download
0
Category
Preview:
Citation preview
FS-415 Electricidad y Magnetismo IIPráctica 1 - Repaso de MathematicaInstructor: Eros RiveraBlog: edanielfisica.wordpress.comCorreo: eros.daniel89@gmail.com
Definiendo Variables y Funciones
In[ ]:= variable := 15
In[ ]:= variable * 15;
In[ ]:= Variable := 20
In[ ]:= cualquiercosa := 11
In[ ]:= F[x_] = 4 *
coseno
Cos[2 * π / x]
Out[ ]= 4 Cos2 π
x
In[ ]:= g[x_, y_] := 7 * x2 + 3 * y2
In[ ]:= F[2]
Out[ ]= -4
In[ ]:= g[3, 5]
Out[ ]= 138
Derivación e Integración
In[ ]:= h[x_] =
coseno
Cos[x]
Out[ ]= Cos[x]
In[ ]:= Der1 =
deriva
D[h[x], x]
Out[ ]= -Sin[x]
In[ ]:=
deriva
D[Der1, x]
Out[ ]= -Cos[x]
In[ ]:=
⋯
D[⋯
D[⋯
D[deriva
D[h[x], x], x], x], x]
Out[ ]= Cos[x]
In[ ]:=
integra
Integrate[seno
Sin[x], x]
Out[ ]= -Cos[x]
In[ ]:= F1[x_] := Cos[x]2
In[ ]:=
integra
Integrate[F1[x], x]
Out[ ]=
x
2+1
4Sin[2 x]
In[ ]:=
integra
Integrate[F1[x], {x, 0, 2 * π}]
Out[ ]= π
In[ ]:=
integra
Integrate[exponencial
Exp[n * x], {x, 0,infinito
Infinity}]
Out[ ]= ConditionalExpression-1
n, Re[n] < 0
2 Practica 1 - Repaso.nb
In[ ]:= IntLim =
simplifica compl⋯
FullSimplify[integra
Integrate[exponencial
Exp[n * x], {x, 0,infinito
Infinity}], n ϵ
números reales
Reals && n < 0]
Out[ ]= -1
n
Funciones Pares e Impares
In[ ]:= f1[x_] = x2 + 1
Out[ ]= 1 + x2
In[ ]:= f1[2]
Out[ ]= 5
In[ ]:= f1[-2]
Out[ ]= 5
In[ ]:= f2[x_] = x3 + x
Out[ ]= x + x3
In[ ]:= f2[3]
Out[ ]= 30
In[ ]:= f2[-3]
Out[ ]= -30
In[ ]:=
co⋯
Cos[número pi
Pi]
Out[ ]= -1
In[ ]:=
cos⋯
Cos[-número pi
Pi]
Out[ ]= -1
Practica 1 - Repaso.nb 3
In[ ]:=
seno
Sinnúmero pi
Pi 2
Out[ ]= 1
In[ ]:=
seno
Sin-número pi
Pi 2
Out[ ]= -1
In[ ]:=
representación gráfica
Plot[f1[x], {x, -5, 5}]
Out[ ]=
-4 -2 2 4
5
10
15
20
25
In[ ]:=
representación gráfica
Plot[f2[x], {x, -5, 5}]
Out[ ]=-4 -2 2 4
-100
-50
50
100
In[ ]:=
integra
Integrate[f1[x], {x, -5, 5}]
Out[ ]=
280
3
4 Practica 1 - Repaso.nb
In[ ]:= 2 *
integra
Integrate[f1[x], {x, 0, 5}]
Out[ ]=
280
3
In[ ]:=
integra
Integrate[f2[x], {x, -10, 10}]
Out[ ]= 0
Ajustes de DatosSupongamos que tenemos los siguientes datos recopiladosX 0 1 2 3 4 5
Y 1.2 3.3 4.2 6.7 7.4 9.2
y queremos escribir esos conjuntos de datos de forma que podamos manipularlos según lonecesitemos.
In[ ]:= Datos = {{0, 1.2}, {1, 3.3}, {2, 4.2}, {3, 6.7}, {4, 7.4}, {5, 9.2}}
Out[ ]= {{0, 1.2}, {1, 3.3}, {2, 4.2}, {3, 6.7}, {4, 7.4}, {5, 9.2}}
Entonces una vez escrito el conjunto de datos, podemos proceder a darle uso según nuestra convenien-cia, como graficarlo o realizar ajustes.
In[ ]:= Grafico =
representación de li⋯
ListPlot[Datos,etiqueta de ejes
AxesLabel → {"Pos(cm)", "Veloc(cm/s)"},
leyendas de representación
PlotLegends → {"Datos Experimentales"},
etiqueta de representación
PlotLabel → "Gráfica 1: Datos Experimentales",estilo de repre⋯
PlotStyle → {
tamaño de⋯
PointSize[grande
Large],azul
Blue}]
Out[ ]=
1 2 3 4 5Pos(cm)
2
4
6
8
Veloc(cm/s)Gráfica 1: Datos Experimentales
Datos Experimentales
Practica 1 - Repaso.nb 5
In[ ]:= Ajuste =
ajusta a modelo lineal
LinearModelFit[Datos, x, x]
Out[ ]= FittedModel 1.41905 + 1.56571 x
In[ ]:= Ajuste["ParameterTable"]
Out[ ]=
Estimate Standard Error t-Statistic P-Value
1 1.41905 0.301196 4.71138 0.00923024x 1.56571 0.0994816 15.7387 0.0000952082
In[ ]:= ALin[x_] =
normal
Normal[Ajuste]
Out[ ]= 1.41905 + 1.56571 x
In[ ]:= Grafico2 =
representación gráfica
Plot[ALin[x], {x, 0, 5},etiqueta de representación
PlotLabel → "Modelo Lineal",
estilo de repre⋯
PlotStyle → {
negro
Black},leyendas de representación
PlotLegends → {"AX+B"},etiqueta de ejes
AxesLabel → {"x", "y"}]
Out[ ]=
1 2 3 4 5x
2
4
6
8
yModelo Lineal
AX+B
In[ ]:=
muestra
Show[ Grafico, Grafico2,etiqueta de representación
PlotLabel → "Graficos Juntos"]
Out[ ]=
1 2 3 4 5Pos(cm)
2
4
6
8
Veloc(cm/s)Graficos Juntos
Datos Experimentales
AX+B
6 Practica 1 - Repaso.nb
Ahora probaremos con un segundo conjunto de datos que muestran un comportamiento diferente.
In[ ]:= Datos2 = {{2, 4}, {3.5, 5.0}, {4.3, 5.8}, {5.2, 6.7}, {6.0, 8.3}}
Out[ ]= {{2, 4}, {3.5, 5.}, {4.3, 5.8}, {5.2, 6.7}, {6., 8.3}}
In[ ]:= Graf =
representación de lista
ListPlot[Datos2,etiqueta de ejes
AxesLabel → {"x", "y"},leyendas de representación
PlotLegends → {"Datos Experimentales 2"},
etiqueta de representación
PlotLabel → "Gráfica 2: Datos Experimentales",estilo de repre⋯
PlotStyle → {
tamaño de⋯
PointSize[grande
Large],rojo
Red}]
Out[ ]=
2 3 4 5 6x
2
4
6
8
yGráfica 2: Datos Experimentales
Datos Experimentales 2
Trataremos estos datos con dos ajustes, primero con un ajuste lineal.
In[ ]:= Ajus1 =
ajusta a modelo lineal
LinearModelFit[Datos2, x, x]
Out[ ]= FittedModel 1.61094 + 1.03549 x
In[ ]:= Ajus[x_] =
normal
Normal[Ajus1]
Out[ ]= 1.61094 + 1.03549 x
In[ ]:= Ajus1["ParameterTable"]
Out[ ]=
Estimate Standard Error t-Statistic P-Value
1 1.61094 0.606131 2.65774 0.0764861x 1.03549 0.137065 7.55474 0.00480923
Practica 1 - Repaso.nb 7
In[ ]:= Grafic =
representación gráfica
Plot[Ajus[x], {x, 2, 7},etiqueta de representación
PlotLabel → "Modelo Lineal",
estilo de repr⋯
PlotStyle →
púrpura
Purple,leyendas de representación
PlotLegends → {"mx+b"},etiqueta de ejes
AxesLabel → {"x", "y"}]
Out[ ]=
3 4 5 6 7x
4
5
6
7
8
9
yModelo Lineal
mx+b
In[ ]:=
muestra
Show[Graf, Grafic]
Out[ ]=
2 3 4 5 6x
2
4
6
8
yGráfica 2: Datos Experimentales
Datos Experimentales 2
mx+b
Intentaremos encontrar una ecuación cuadrática para ajustarla a los datos.
AjusNolineal =
ajusta a modelo no lineal
NonlinearModelFitDatos2, A *exponencial
Expt τ, {A, τ}, x
Out[ ]= FittedModel 4.08363 - 0.381475 x + 0.177877 x2
8 Practica 1 - Repaso.nb
In[ ]:= AjusNolineal["ParameterTable"]
Out[ ]=
Estimate Standard Error t-Statistic P-Value
a 0.177877 0.0466206 3.81542 0.0623389b -0.381475 0.375934 -1.01474 0.417018c 4.08363 0.697547 5.85427 0.02796
a = ( 0.18 ± 0.05 ) unidadesb = (-0.4 ± 0.4 ) unidadesc = ( 4.1 ± 0.7 ) unidades
In[ ]:= AjuNoLin[x_] =
normal
Normal[AjusNolineal]
Out[ ]= 4.08363 - 0.381475 x + 0.177877 x2
In[ ]:= GrafNoLin =
representación gráfica
Plot[AjuNoLin[x], {x, 2, 7},estilo de repr⋯
PlotStyle →
verde
Green,
leyendas de representación
PlotLegends → {"Cuadrático"},etiqueta de ejes
AxesLabel → {"x", "y"},rango de representación
PlotRange → {3, 8.5}]
Out[ ]=
2 3 4 5 6 7x
4
5
6
7
8
y
Cuadrático
Practica 1 - Repaso.nb 9
In[ ]:=
muestra
Show[Graf, GrafNoLin]
Out[ ]=
2 3 4 5 6x
2
4
6
8
yGráfica 2: Datos Experimentales
Datos Experimentales 2
Cuadrático
In[ ]:= Datos3 = {{1, 2.1}, {2, 2.9}, {3, 4.3}, {4, 4.5}, {5, 6.7}}
Out[ ]= {{1, 2.1}, {2, 2.9}, {3, 4.3}, {4, 4.5}, {5, 6.7}}
In[ ]:= AjusteA =
ajusta a modelo lineal
LinearModelFit[Datos3, x, x]
Out[ ]= FittedModel 0.86 + 1.08 x
In[ ]:= FuncA[x_] =
normal
Normal[AjusteA]
Out[ ]= 0.86 + 1.08 x
In[ ]:= AjusteA["ParameterTable"]
Out[ ]=
Estimate Standard Error t-Statistic P-Value
1 0.86 0.519487 1.65548 0.196403x 1.08 0.156631 6.89518 0.00625014
In[ ]:= AjusteB =
ajusta a modelo no lineal
NonlinearModelFitDatos3, 0.5 h * x2 + u, {h, u}, x
Out[ ]= FittedModel 2.14706 + 0.17754 x2
10 Practica 1 - Repaso.nb
In[ ]:= FuncB[x_] =
normal
Normal[AjusteB]
Out[ ]= 2.14706 + 0.17754 x2
In[ ]:= AjusteB["ParameterTable"]
Out[ ]=
Estimate Standard Error t-Statistic P-Value
h 0.35508 0.0466846 7.60593 0.00471657u 2.14706 0.326626 6.57346 0.0071621
In[ ]:= GraficaA :=
representación gráfica
Plot[FuncA[x], {x, 0, 6},estilo de repre⋯
PlotStyle → {
negro
Black,rayado
Dashed},leyendas de representación
PlotLegends → {"Ajuste Lineal"}]
In[ ]:= GraficaB :=representación gráfica
Plot[FuncB[x], {x, 0, 6},
estilo de repre⋯
PlotStyle → {
naranja
Orange,punteado
Dotted,grueso
Thick},leyendas de representación
PlotLegends → {"Ajuste Cuadrático"}]
In[ ]:= GraficaDatos :=
representación de lista
ListPlot[Datos3,estilo de repre⋯
PlotStyle → {
púrpura
Purple,tamaño de punto
PointSize[0.015]},leyendas de representación
PlotLegends → {"Datos"}]
In[ ]:=
muestra
Show[GraficaA, GraficaB, GraficaDatos,
etiqueta de representación
PlotLabel → "Ejemplo Final",etiqueta de ejes
AxesLabel → {"Independiente", "Dependiente"}]
Out[ ]=
1 2 3 4 5 6Independiente
2
3
4
5
6
7
DependienteEjemplo Final
Ajuste Lineal
Ajuste Cuadrático
Datos
Practica 1 - Repaso.nb 11
In[ ]:= Disc =
represe⋯
ListPlot{
valor con incer⋯
Around[1, 0.2],
valor con incertid⋯
Around[0.35, 0.05],
valor con incertidumbre
Around[0.7, 0.15]},
rango de representación
PlotRange → {{0, 4}, {0, 1.5}},
marco
Frame →
verdadero
True,
marcas del ⋯
FrameTicks →
automát⋯
Automatic,
ninguno
None, 1, "Lineal", 2, "Cuadratico", 3, "Exponencial",
ninguno
None,
PlotLegends → "Mediciones",
etiqueta de representación
PlotLabel → "Gráfico de Discrepancia"
Out[ ]=
Lineal Cuadratico Exponencial0.0
0.2
0.4
0.6
0.8
1.0
1.2
1.4
Gráfico de Discrepancia
Mediciones
In[ ]:= Ref =
representación gráfica
Plot[1, {x, 0, 4},estilo de represe⋯
PlotStyle → {
rojo
Red,delgado
Thin},leyendas de representación
PlotLegends → {"Valor Teórico"}]
Out[ ]=
1 2 3 4
0.5
1.0
1.5
2.0
Valor Teórico
In[ ]:=
muestra
Show[Disc, Ref]
Out[ ]=
Lineal Cuadratico Exponencial0.0
0.2
0.4
0.6
0.8
1.0
1.2
1.4
Gráfico de Discrepancia
Mediciones
Valor Teórico
12 Practica 1 - Repaso.nb
Ejemplo de Electromagnetismo - Inducción MagnéticaEn la pagina 282 del libro de texto se encuentra la Inducción Magnética producida por una corrienterecta de longitud finita. Calcularemos el Campo B
In[ ]:=
In[ ]:= SetCoordinates[Cylindrical];
In[ ]:= dB[z_] = 0,μ * L * ρ
4 * π ρ2 + z23/2, 0;
In[ ]:=
asumiendo
Assuming[L ϵ
números reales
Reals && ρ > 0 && ρ ϵ
números reales
Reals && L1 > 0 && L2 > 0 && L1 ϵ
números reales
Reals && L2 ϵ
números reales
Reals,
integra
Integrate[dB[z], {z, -L1, L2}]]
Out[ ]= 0,
L μL1
L12+ρ2+
L2
L22+ρ2
4 π ρ, 0
StreamPlot de Inducción B
In[ ]:= SetCoordinates[Cartesian];
In[ ]:= a = 2
L = 10
Out[ ]= 2
Out[ ]= 10
In[ ]:= B1[ρ_, z_] := -L - 2 z2 + 4 ρ2
L - 2 z+
L - 2 z2 + 4 ρ (-a + ρ)
L - 2 z L - 2 z2 + 4 (a - ρ)2
Practica 1 - Repaso.nb 13
In[ ]:= B2[ρ_, z_] :=2 a
L - 2 z2 + 4 (a - ρ)2
-
logaritmo
Log2 a + L - 2 z2 + 4 (a - ρ)2
- 2 ρ +
logaritmo
Log-2 ρ + L - 2 z2 + 4 ρ2
In[ ]:=
representación de flujo
StreamPlot[{B1[ρ, z] + B1[ρ, -z], B2[ρ, z] - B2[ρ, -z]},
{z, -20, 20}, {ρ, -20, 20},tamaño de imagen
ImageSize → {595, 400},cociente de aspecto
AspectRatio → .75]
Out[ ]=
-20 -10 0 10 20
-20
-10
0
10
20
14 Practica 1 - Repaso.nb
Análogo al Dipolo
Practica 1 - Repaso.nb 15
Recommended