Beruflich Dokumente
Kultur Dokumente
POR EL USUARIO
Cos(x)
se llama cos,
toma la entrada del usuario dentro de parntesis (en este
caso, x), y
calcula un resultado.
function salida =
mi_funcin(x)
Y= 2X
la palabra function,
una variable que defina la salida de funcin,
un nombre de funcin, y
una variable que se use para el argumento de entrada.
salida
function salida =
mi_funcin(x)
function resultado = polinomio( x )
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
resultado= 2*x.^2+ 2*x+1;
>> polinomio(2)
>> x= [ 1 2 3 4 5 6]
x=
1
>> polinomio(x)
ans =
5
13
25
41
61
85
61
85
>> y= [ 1 2 3 4 5 6];
>> polinomio(y)
ans =
5
13
25
41
jerciciodeprctica
E
Cree funciones MATLAB para evaluar las siguientes funciones matemticas
(asegrese de seleccionar nombres de funcin significativos):
Y(x) = x^2
Y(x) =
Y(x)= seno(x^2)
Cree funciones MATLAB para las siguientes conversiones de unidades (es posible
que
necesite consultar un manual o Internet para los factores de conversin
adecuados):
4. pulgadas a pies
5. caloras a joules
6. watts a BTU/h
7. metros a millas
8. millas por hora (mph) a pies/s
y1= x+y;
end
>> x=1:10;
[f, g, h]=m(x)
m(2,3)
function [ y1 ] = m( x,y )
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
function [ y1 ] = m( x,y )
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
y1= x+y;
end
y1= x+y;
y2= x-y;
end
En la ventana de comandos escriba:
[y1, y2]=m(9,5)
>> [z1,
z2]=m(9,5)
escriba sus conclusiones:
cree y ponga a prueba funciones MATLAB para evaluar las siguientes funciones matemticas
simples con vectores de entrada mltiple y un vector de salida sencilla:
cree y ponga a prueba funciones MATLAB para evaluar las siguientes funciones matemticas
simples con un vector de entrada sencilla y vectores de salida mltiple:
cree y ponga a prueba funciones MATLAB para evaluar las siguientes funciones matemticas
simples con vectores de entrada mltiple y un vectores de salida multiple:
function [ ] = m( )
% mi primera funcion
%
Detailed explanation goes here
teta=pi/2:0.8*pi:4.8*pi;
r=ones(1,6);
polar(teta,r)
end
a = clock
Help m
Variables locales
function [ r ] = multiplica( x, y )
% Esta funcin multiplica dos nmeros que
deben ser ingreados entre parntesis y
separados por coma
r= x*y;
end
>> clc, clear
>> multiplica(3,3)
>> x
>> y
>> r
>> nargin('multiplica')
ans =
2
>> nargout('multiplica')
ans =
1
Variables locales
function [ r ] = f( t )
%UNTITLED2 Summary of this function goes
here
%
Detailed explanation goes here
r= 0.5*g.*t^2;
end
function [ r ] = f( t )
%UNTITLED2 Summary of this function goes
here
%
Detailed explanation goes here
g=9.8;
r= 0.5*g.*t^2;
end
>> f(3)
Variables locales
function [ r ] = f( t )
%UNTITLED2 Summary of this function goes
here
%
Detailed explanation goes here
g=9.8;
r= 0.5*g.*t^2;
end
>> f(3)
Variables locales
function [ r ] = f( t,g )
%UNTITLED2 Summary of this function goes
here
%
Detailed explanation goes here
r= 0.5*g.*t^2;
end
Variables globales
function [ r ] = f( t )
%UNTITLED2 Summary of this function goes
here
%
Detailed explanation goes here
global G;
r= 0.5*G.*t^2;
end
>>
G=9.8;
>> f(3)
>> global G;
>> G=9.8;
>> G=2;
>> f(3)
>>
type f
>> type
sphere
FUNCIONES ANNIMAS
>> w= @(x,y)
x^2+y^2;
>> w(2,2)
>>
>>
>>
>>
y=@ sin
y(1)
sin(1)
fplot(y, 0:1)