Documentos de Académico
Documentos de Profesional
Documentos de Cultura
clc
clear all
%convercion de temperaturas
C=input('ingrese grados celsius (C):');%ingrese datos en celsius
disp('
F
K')
%los resutados son
F=(9/5)*C+32;%Fahrenheit
K=C+273.15;%kelvin
disp([F
K])
Ejemplo 2
clc
clear all
%parametros de entrada
c=input('ingrese grados celsius C:');
%conversion
k=c+273.15;
f=(9/5)*c+32;
%asignacion de mensaje
mssg=['temperatura en K es:' num2str(k)];
mssg2=['la temperatura en F es:' num2str(f)];
%presentacion del mensaje
disp(mssg)
disp(mssg2)
Ejemplo 3
clc
clear all
%% parametros
%calculo de la entalpia
T1=300;%en kelvin
T2=591;%en kelvin
a=28.90;
b=(0.1967*10^(-2));
c=(0.4802*10^(-5));
d=(-1.966*10^(-9));
ht=8900;
%% calculo
format bank %expresa en el formato en dos cifras significativas
h=a*(T2-T1)+(b/2)*(T2^2-T1^2)+(c/3)*(T2^3-T1^3)+(d/4)*(T2^4-T1^4);
%% error
e=(ht-h)*100/ht%porcentaje de error
Ejemplo 4 trucos
y=1:5
y =
1.00
5.00
2.00
3.00
4.00
pares=2:2:10
pares =
2.00
4.00
10.00
Ejemplo 4
M([1,2],[2,3])
ans =
2.00
3.00
5.00
6.00
Ejemplo 4
>> M=[1,2,3;4,5,6;7,8,9];
>> M2=[20,21,22;M]
M2 =
20.00
21.00
1.00
2.00
3.00
4.00
5.00
6.00
7.00
8.00
9.00
22.00
M3=[[15;16;17],M]
M3 =
15.00
1.00
2.00
3.00
6.00
8.00
16.00
17.00
Ejemplo 1
ans =
>> ones(2,3)
ans =
>> ones(3)
ans =
EJEMPLO 2
A=[1 2 3;3 4 5;1 2 3];
>> diag(A)
4.00
7.00
5.00
8.00
6.00
9.00
ans =
1
4
3
ans =
>> dot(a,b)
ans =
32
>> cross(a,b)
ans =
-3
6 -3
>> cross(b,a)
ans =
3 -6
Ejemplo 3
t=0:pi/20:2*pi;
plot(t,sin(t),'-.r')
hold on: GRAFICA TODO EN UNA SOLA GRAFICA
plot(t,sin(t-pi/2),'--mo')
plot(t,sin(t-pi),'bs')
legend('sin','sin(t-pi/2)','sen(t-pi)')
hold off:
GRAFICAS LOGARITMICAS
x=0:pi/20:2*pi;
y1=sin(x);
y2=exp(x);
subplot(2,1,1);
plot(x,y1,x,y2);
subplot(2,1,2)
plotyy(x,y1,x,y2);GRAFICA CON RANGOS DIFERENTES
GRAFICOS 3D
clc;clear all
x=linspace(1,50,5)
y=linspace(500,100,3)
z=[1 2 3 4 5;
2 4 6 8 10;
3 4 5 6 7];
mesh(x,y,z);
%%
clc;clear all
x1=-2:.1:2
y1=-2:.1:2
[X1 Y1]=meshgrid(x1,y1)
Z1=X1.*exp(-X1.^2-Y1.^2)
subplot(2,2,1)
mesh(X1,Y1,Z1)
subplot(2,2,2)
surf(X1,Y1,Z1)
subplot(2,2,3)
contour(X1,Y1,Z1)
subplot(2,2,4)
surfc(X1,Y1,Z1)
x=-10:0.01:10;
k=-1;
y=k*(x.^2)-2;
h=plot(x,y);
grid on
hold on
%set(h,erasemode','xor')
axis([-10,10,-100,100])
while k<1
k=k+0.01;
y=k*(x.^2)-2;
%h=plotx,y);
set(h,'XData',x,'Ydata',y);
drawnow
end