, , MATLAB.
@ , .
inline.
.
, MATLAB , , , , ^, *.
:
>> f = @(x) x.^2.*sin(pi*x/2)
f =
@(x)x.^2.*sin(pi*x/2)
:
>> f1 = inline('x.^2.*sin(pi*x/2)')
f1 =
Inline function:
f1(x) = x.^2.*sin(pi*x/2)
, , ,
>> a = f(3)
a =
-9
>> a = f1(3)
a =
-9
>> x = [1 2 3]
x =
1 2 3
>> a = f(x)
a =
1.0000 0.0000 -9.0000
>> a = f1(x)
a =
1.0000 0.0000 -9.0000
.
, .
>> g = @(x,y) (x+y).*exp(x)
g =
@(x,y)(x+y).*exp(x)
>> g1 = inline('(x+y).*exp(x)','x','y')
g1 =
Inline function:
g1(x,y) = (x+y).*exp(x)
>> x = [1 2]
x =
1 2
>> y = [2.5 3.4]
y =
2.5000 3.4000
>> u = g(x,y)
u =
9.5140 39.9009
>> u = g1(x,y)
u =
9.5140 39.9009
-.
- , , .
- File MatLab New M-file. -.
, , .
------------------------------------------------------------------------------------------------------------------------
A = [2 1 -0.1 1
0.4 0.5 4 -8.5
0.3 -1 1 5.2
1 0.2 2.5 -1]
B = [2.7; 21.9; -3.9; 9.9]
D = [A B]
-----------------------------------------------------------------------------------------------------------------------
, , proba , Save as File . -, Run Debug ( F5).
- , %. , :
------------------------------------------------------------------------------------------------------------------------
%
A = [2 1 -0.1 1
0.4 0.5 4 -8.5
0.3 -1 1 5.2
1 0.2 2.5 -1];
%
B = [2.7; 21.9; -3.9; 9.9];
% D
D = [A B];
% D
disp(' D = ')
disp(D)
|
|
------------------------------------------------------------------------------------------------------------------------
.
disp, .
- Open File, -.
7. -.
- .
, -, , , . ,
.
-
------------------------------------------------------------------------------------------------------------------------
function f = myfun(x)
f = exp(-x).*sqrt((x.^4 + 1)./(x.^4 + 0.1));
-----------------------------------------------------------------------------------------------------------------------
function , -; myfun ; x ; f . , , , . , , , f.
; .
myfun.
, sin, cos, . ,
>> y = myfun(1.3)
y =
0.3113
, , , , :
>> x = [1.3 7.2];
>> y = myfun(x)
y =
0.3113 0.0007
- .
-, -
.
- . :
------------------------------------------------------------------------------------------------------------------------
function r = radius3(x, y, z)
r = sqrt(x.^2 + y.^2 + z.^2);
------------------------------------------------------------------------------------------------------------------------
radius3. , :
>> R = radius3(1, 1, 1)
R =
1.732
- .
- -. , . , , , , , .
-----------------------------------------------------------------------------------------------------------------------
function [h, m, s] = hms(sec)
h = floor(sec/3600);
m = floor((sec-h*3600)/60);
s = sec h*3600 m*60;
------------------------------------------------------------------------------------------------------------------------
- :
|
|
>> [H, M, S] = hms(10000)
H =
M =
S =
,
function funname() function [] = funname().