Professional Documents
Culture Documents
"
# " $
"
% " & !
!
Alba Giraldo
' (
) "
) # & *
#
+ # , # $
'
- "
!" ./01
' " $
"
2 "
& # (
Alba Giraldo
% -
3 " (
"
" $
Alba Giraldo
4 5
7
Alba Giraldo
6 -
3 ,
# ( 8
'89 -2)
-75:;9
%
" <
(
8
Alba Giraldo
= -
> 3
? @
A
B 6
C %
9 6 (
Alba Giraldo
= -
@ ! " 8
D>E
DAF
;BD
D9;
ECD
ECD<
Alba Giraldo
4
3
4 3
G8 Volumen = πr
3
>> r=2
>> r=2 =
rr == $
2
22
>> vol=(4/3)*pi*r^3
>> vol=(4/3)*pi*r^3
vol ==
vol
33.5103
33.5103
Alba Giraldo
%
( 8
r=2;vol=(4/3)*pi*r^3
' ( " #
#
! ↑↓
(
2 !
command history
4
) 8
>> numero_de_visitantes=25
numero_de_visitantes =
25
>> Nombre='Pepe'
Nombre =
Pepe
Alba Giraldo
@"
3 !
, (" : H# " IJK
#* #
*
6 ! #
L ! 8
) # .2 # 1
L
L
Alba Giraldo
L 4
ans
pi π
inf
NaN
i, j √
eps !"
date # $%
Alba Giraldo
M 4
N
NNN
%
& * OO
DD;E
;E;P
;P
. 1
F
"
3 N
NNN "
"
" N
NNN
OO
" DD;E
;E;F
;FHHGP
GPFFDF
DFQQ
HH
55
HH
Alba Giraldo
M
% "
" (
0 "
R ,
, # !
8
>> [t,h]=ode45(‘twotnk’,[0
>> [t,h]=ode45(‘twotnk’,[0 100],[12,7]);
100],[12,7]);
L -"
Alba Giraldo
M
& $ sin, cos, tan, sin, acos, atan,
$ sinh, cosh, tanh, asinh,
acosh, atanh, csc, sec, cot,
acsc, …
' exp, log, log10, sqrt
$
( ' abs, angle, imag, real, conj
$
sin(pi/2) %Calcula el seno del ángulo dado en radianes
exp(0) %Eleva a la cero la base de los logaritmos neperianos:e0
abs(2+6i) %Calcula el valor absoluto o la norma de un número
%imaginario Alba Giraldo
-#
3 " ,
help # 8
>> help
>> help sqrt
sqrt
SQRT Square
SQRT Square root.
root.
SQRT(X) is
SQRT(X) is the
the square
square root
root of
of the
the elements
elements of
of X.
X. Complex
Complex
results are
results are produced
produced if
if XX is
is not
not positive.
positive.
See also
See also sqrtm.
sqrtm.
Overloaded functions
Overloaded functions or
or methods
methods (ones
(ones with
with the
the same
same name
name
in other
in other directories)
directories)
help sym/sqrt.m
help sym/sqrt.m
Reference page
Reference page in
in Help
Help browser
browser
doc sqrt
doc sqrt
Alba Giraldo
4 "
%
% " 8
>> t=[3
>> t=[3 55 7,8,9]
7,8,9]
>> z=[1;2;3;4]
>> z=[1;2;3;4]
>> z=[1
>> z=[1 22 33 4]'
4]'
>> z=z'
>> z=z'
Alba Giraldo
M "
>> x=linspace(0,20,5)
>> x=linspace(0,20,5)
xx ==
00 55 10
10 15
15 20
20
>> y=0:5:20
>> y=0:5:20
yy ==
00 55 10
10 15
15 20
20
>> x1=linspace(0,20);
>> x1=linspace(0,20);
>> y1=0:20;
>> y1=0:20;
>> z=logspace(0,2,5)
>> z=logspace(0,2,5) %Vector
%Vector de
de 55 elementos
elementos de
de 10^0
10^0 aa 10^2
10^2
zz ==
1.0000
1.0000 3.1623
3.1623 10.0000
10.0000 31.6228 100.0000
31.6228 100.0000
Alba Giraldo
4 "
% ! ST#
>> A=[1
>> A=[1 2;3
2;3 4;5
4;5 6]
6]
AA ==
11 22
33 44
55 66
>> B=[1
>> B=[1 22 3;4
3;4 55 6]
6]
BB ==
11 22 33
44 55 66
Alba Giraldo
' # "
>> x=0:4;
>> x=0:4;
>> y=10:14;
>> y=10:14;
>> a=[x;y]
>> a=[x;y]
aa ==
00 11 22 33 44
10
10 11
11 12
12 13
13 14
14
>> b=[x',y']
>> b=[x',y']
bb ==
00 10
10
11 11
11
22 12
12
33 13
13
44 14
14
Alba Giraldo
- #- "
>> y(3)
>> y(3)
ans ==
ans
12
12
>> b(1,1)
>> b(1,1)
ans ==
ans
00
>> b(10,1)
>> b(10,1)
??? Index
??? Index exceeds
exceeds matrix
matrix dimensions.
dimensions.
>> size(b)
>> size(b)
ans ==
ans
55 22
>> length(b)
>> length(b)
ans ==
ans
55
Alba Giraldo
= "
>> A=[1
>> A=[1 22 ;3
;3 4;5
4;5 6]
6] ' "
>> B=[6
>> B=[6 5;4
5;4 3;2
3;2 1]
1] !
>> C=2*A
>> C=2*A , #
>> D=A/2
>> D=A/2 #
>> E=A+B
>> E=A+B
>> F=A.^2
>> F=A.^2
>> G=A.*B
>> G=A.*B
>> H=A./B
>> H=A./B
>> x=linspace(0,30);
>> x=linspace(0,30);
>> y=2*x.^2;
>> y=2*x.^2;
' $ !
clear "
Alba Giraldo
= "
>> C=[3
>> C=[3 22 -1;-1
-1;-1 33 2;1
2;1 -1
-1 -1];
-1]; '
>> X=[-2
>> X=[-2 55 -6]'
-6]' !
>> Y=C*X
>> Y=C*X
YY ==
10
10
55 "
-1
-1
>> x=C/Y
>> x=C/Y
??? Error
??? Error using
using ==>
==> mrdivide
mrdivide
Matrix dimensions
Matrix dimensions must
must agree.
agree.
>> x=C\Y
>> x=C\Y
xx ==
-2.0000
-2.0000 ' U
5.0000
5.0000
-6.0000
-6.0000
Alba Giraldo
M
>> size(C)
>> size(C) %Dimesión de
%Dimesión de la
la matriz
matriz CC
ans ==
ans
33 33
>> det(C)
>> det(C) %Determinante
%Determinante
ans ==
ans
11
>> rank(C)
>> rank(C) %Rango de
%Rango de la
la matriz
matriz
ans ==
ans
33
>> inv(C)
>> inv(C) %Matriz inversa
%Matriz inversa
ans ==
ans
-1.0000
-1.0000 3.0000
3.0000 7.0000
7.0000
1.0000 -2.0000
1.0000 -2.0000 -5.0000
-5.0000
-2.0000
-2.0000 5.0000
5.0000 11.0000
11.0000
>> eig(C)
>> eig(C) %Raíces características
%Raíces características
ans ==
ans
0.1363
0.1363
2.4319 ++ 1.1930i
2.4319 1.1930i
2.4319 -- 1.1930i
2.4319 1.1930i
Alba Giraldo
- "
N
NNN ## .G1
.G1
. 1
OO
. ,1
;; ::
! . 1 :: ;;
N N ## .G,
.G,D1
! . ,1 NN D1
# . 1 OO
;; :: :
:
# . ,1 :: ;; :
:
Alba Giraldo
/
2500
» x = 1:2:50; y=x 2
» y = x.^2
2000
»plot(x,y)
» xlabel('Values of x') Valores de Y 1500
» ylabel('y')
1000
» grid
» legend('y=x^2') 500
» xlabel('Valores » de X') 0
0 5 10 15 20 25 30 35 40 45 50
Valore s de X
» ylabel('Valores » de Y')
Alba Giraldo
' fplot
;O 4
V.&1&CG
NN . ;,
S:F:T
1
)
( "
)
( "
Alba Giraldo
*
"
4
x 10
3
y=x 2
y=x 3
NN #;O& CG< 2.5
y=30*x 2
2
NN #GO& CD<
1.5
NN #DOD:A& CG<
1
NN #OS
#;<
#G<
#DT
<
0.5
NN .&,
#1 0
0 5 10 15 20 25 30
NN " .X
#O&CGX
,X
#O&CDX
,X
#OD:A&CGX
1
Alba Giraldo
*
"
4
x 10
3
2.5
>> plot(x,y1)
2
>> hold
1.5
Current plot held
1
>> plot(x,y2,'*')
0.5
>> plot(x,y3,'o')
0
0 5 10 15 20 25 30
Alba Giraldo
*
"
4
x 10
3
>> fn1=@(x)x^2
fn1 =
@(x)x^2 2.5
>> fn2=@(x)x^3
2
fn2 =
@(x)x^3
1.5
>> fn3=@(x)30*x^2
fn3 =
1
@(x)30*x^2
>> fplot(fn1,[0 50])
0.5
>> fplot(fn1,[0 50])
>> hold
Current plot held 0
0 5 10 15 20 25 30
>> fplot(fn2,[0 50],'*')
>> fplot(fn3,[0 50],'o')
Alba Giraldo
/ "# "
>> P=logspace(3,7); >> x=linspace(0,100);
>> Q=0.079*P.^(-0.24); >> y=500*exp(0.1*x);
>> loglog(P,Q),grid >> semilogy(x,y)
8
10
-1 10
7
10
6
10
-2 5
10 10
4
10
3
10
-3
10 2
3 4 5 6 7 10
10 10 10 10 10 0 10 20 30 40 50 60 70 80 90 100
Alba Giraldo
/ %
Gráfica de un Cardioide
90 2
3 " " 8 120 60
1.5
150 1 30
180 0
NN O .:,
GA 1<
210 330
NN O;? . 1<
240 300
NN . ,1 270
NN .X
/ ' X
1
Alba Giraldo
3 "
subplot
" ,
"
8
subplot(2,2,1),loglog(P,Q),grid;
subplot(2,2,1),loglog(P,Q),grid;
subplot(2,2,2),semilogy(x,y),grid;
subplot(2,2,2),semilogy(x,y),grid;
subplot(2,2,3),polar(t,r);
subplot(2,2,3),polar(t,r);
subplot(2,2,4),fplot(fn1,[0 50]);
subplot(2,2,4),fplot(fn1,[0 50]);
Alba Giraldo
$
-1 8
10 10
6
10
-2
10
4
10
-3 2
10 10
10
0
10
5
10
10 0 50 100
90 2 2500
120 60
1 2000
150 30
1500
180 0
1000
210 330
500
240 300
270 0
0 10 20 30 40 50
Alba Giraldo
/
3 ! "
3 " " 8
1
z = f ( x, y ) =
1 + x2 + y2
' & ?G # G #
# ?; # G
Alba Giraldo
/
3 &,
#8 >> x=linspace(-2,2);
' meshgrid 3 >> y=linspace(-1,2);
(
&# >> [x3d,y3d]=meshgrid(x,y);
# R
( &,
#
3 * >> z=1./(1+x3d.^2+y3d.^2);
Alba Giraldo
/
0.8
0.6
0.4
0.2
0
2
2
1
1
0 0
-1
-1 -2
Alba Giraldo
%
Representación de un polinomio en Matlab :
y=2x4+4x3-14x2-16x+24
se representa como el siguiente vector fila:
>> p=[2 4 -14 -16 24]
p=
2 4 -14 -16 24
La función roots calcula todas las raíces del polinomio:
>> r=roots(p)
r=
-3.0000
-2.0000
2.0000
1.0000
Alba Giraldo
%
Cuando se conocen las raíces de un polinomio el
comando poly lo recalcula:
>> poly(r)
ans =
1.0000 2.0000 -7.0000 -8.0000 12.0000
>> xi=2.5;
>> yi=polyval(p,xi)
yi =
37.1250
Alba Giraldo
/
>> x=linspace(-4,3);
>> y=polyval(p,x);
>> plot(x,y)
60
50
40
30
20
10
-10
-4 -3 -2 -1 0 1 2 3
Alba Giraldo
?M
"
% " $
"
'
!"
Alba Giraldo
' ?
"
L ?
= *
M B
L B ?M
Alba Giraldo
' ( . 1 "
$
'
flow.m
function [NRe, f] = flow(D,v,rho,mu)
% flow(Diamter, Velocity, Density, % Viscosity)
% Outputs NRe and f
% Done on 22-Feb-2002
NRe = D*v*rho/mu;
f = 0.079*NRe^(-0.25);
) " $
N
NNNSS
@@;,
;,;T
;TOO .D,
.D,;;F
F,
,H
H:
::
:,
,::
: :;1
;1
@;;OO
@
E
E:
:F
F::
::
::
;;OO
::::
::D;
D;
N
NNN
Alba Giraldo
L
-$ '
#
$ (
< & 8 # .&,
#,1
>> xx == [1
>> [1 33 77 21];
21]; %Vector de
%Vector de variable
variable independiente
independiente
>> yy == [2
>> [2 99 20
20 55];
55]; %Vector de
%Vector de variable
variable dependiente
dependiente
>> coef=polyfit(x,y,2)
>> coef=polyfit(x,y,2) %Ajustando un
%Ajustando un polinomio
polinomio de
de grado
grado 22
coef ==
coef
-0.0251 3.1860
-0.0251 3.1860 -0.8502
-0.8502
>> polyval(coef,1)
>> polyval(coef,1) %Verificando ajuste
%Verificando ajuste del
del polinomio
polinomio
ans ==
ans
2.3108
2.3108
Alba Giraldo
3
3 8
D& >G# ? ! O;:
?& >D# >G! OF
& ?# ? ! O?;
8
3 2 −1 x1 10
A = −1 3 2 x = x2 y= 5
1 −1 −1 x3 -1
Alba Giraldo
3
! -#
Z >> A=[3 2 -1;-1 3 2;1 -1 -1];
>> Y=[10 5 -1]';
3 >> X=inv(A)*Y
X=
-2.0000
5.0000
-6.0000
0 ! ! >> X=A\Y
X=
-2.0000
-
5.0000
-6.0000
3
DQ:[# ;E 8
1 4.9340 h
Z= −
1− h Tr
1.5
1+ h
0.08664Pr
h=
Z Tr
Alba Giraldo
!
function y=zisobutano(Z)
Tc=408.1; %Tc para el isobutano en K
Pc=36.5; %Pc para el isobutano en bar
T=380; )
P=14; !
Pr=P./Pc;
Tr=T./Tc;
h=0.08664.*Pr./(Z.*Tr); $
y=(1./(1-h))-(4.9340./Tr.^1.5).*(h./(1+h))-Z;
6 8
zeta=fzero('zisobutano',1)
zeta=fzero('zisobutano',1)
Alba Giraldo
3
0 "
" 8
Qin
A1 dH1 Qin − K 1 H1 − H2
A2 =
dt A1
H1
H2 Qout
dH2 K 1 H1 −H2 − K 2 H2
Qout1
=
dt A2
3
OG,[;O[GO:,
F-;O; -GOG
Alba Giraldo
3
function dhdt=alturasEE(h)
% To solve
% dh1/dt = (Qin-K1*sqrt(h1-h2))./A1
% dh2/dt =(K1*sqrt(h1-h2)-K2*sqrt(h2))./A2
% When system is stable
% Qin=1;K1=0,5;K2=0,5
dhdt=zeros(2,1);
h1=h(1);h2=h(2)
dhdt(1) = 1-0.5*sqrt(h1-h2);
dhdt(2) = 0.5*sqrt(h1-h2)-0.5*sqrt(h2);
6 8
H=fsolve('alturasEE',[10 10]')
H=fsolve('alturasEE',[10 10]')
Alba Giraldo
) "
" 8
Qin
A
dH Qin − K H
=
H dt A
Qout
3 O:
+OE# OG
Alba Giraldo
3 =6 \
6 8
[t,h]=ode45('onetank',[0 100],4);
[t,h]=ode45('onetank',[0 100],4);
plot(t,h)
plot(t,h)
Alba Giraldo
3
0 "
" 8
Qin
A1 dH1 Qin − K 1 H1 − H2
A2 =
dt A1
H1
H2 Qout
dH2 K 1 H1 −H2 − K 2 H2
Qout1
=
dt A2
3 O:8 OG,
+;OQ +GOE
Alba Giraldo
3 =6 \
6 8
[t, h]
[t, h] == ode45('twotnk',
ode45('twotnk', [0
[0 100],
100], [8
[8 4]');
4]');
plot(t,h)
plot(t,h)
Alba Giraldo
3
& 3
' ! ,
" !
# &
"
syms
>> syms
>> syms xx yy aa bb tt
Alba Giraldo
4 3
-
&
>> s11=x^3-1;
>> s11=x^3-1;
>> s21=(x-3)^2+(y-4)^2;
>> s21=(x-3)^2+(y-4)^2;
>> s31=sqrt(a^4*b^7);
>> s31=sqrt(a^4*b^7);
>> s41=14*x^2/(22*x*y);
>> s41=14*x^2/(22*x*y);
>> s51=(1-t^3)/(1+t^4);
>> s51=(1-t^3)/(1+t^4);
>> S61=sin(a);
>> S61=sin(a);
>> S71=x^(1/2);
>> S71=x^(1/2);
' &
&
# #&
# & Alba Giraldo
3 &
' @
>> pretty(s41)
7/11 x/y
Alba Giraldo
6
' @
− 3
t2
−4
(1 − t3 )t3
(1 + t4 )2
>> pretty(diff(s51))
1 + t4
Alba Giraldo
" 3
' @
Alba Giraldo
/
3
x 1/2
NN ! . 5;,
S:;:T
1 3
NN "
2.5
)
(
2
)
( 1.5
0.5
0 1 2 3 4 5 6 7 8 9 10
x
Alba Giraldo