Differences between revisions 1 and 6 (spanning 5 versions)
Revision 1 as of 2025-10-22 18:53:49
Size: 1661
Comment: Initial commit
Revision 6 as of 2025-12-17 19:51:44
Size: 2538
Comment: Notes
Deletions are marked like this. Additions are marked like this.
Line 20: Line 20:
}}}

A shorthand for an array of sequential numbers (with an optional step parameter) is:

{{{
a = 5:8;
b = 20:2:24;
Line 108: Line 115:
----



== Symbolic Variable ==

Symbolic variables are created like:

{{{
% Declaring symbolic variables.
syms x y;

% Defining symbolic expressions.
f = (x^2 + y^2);

% Defining symbolic functions.
f(x,y) = (x^2 + y^2);
}}}

Symbolic functions can then be evaluated for input values.

Symbolic expressions are very similar, but can be used to define a surface to plot or to solve a system.

{{{
% Define a quadratic equation.
f = a*x^2 + b*x + c

% Solve for roots of a quadratic equation.
x_0 = solve(f == 0, x);
}}}

----



== Function Handle ==

Function handles are created like:

{{{
% Declaring symbolic variables needed by the function handle.
syms x y z;

f = @(x,y,z) (x.^2 + y.^2 + z.^2);
}}}

MATLAB Data Types

MATLAB exposes numeric, character array, and string data types.


Numeric

All numeric variables are arrays. Colloquially, an array with a single element is called a scalar.

By default, all numeric values are stored as double-precision floating point. Other storage sizes are available however.

x = 3;
y = [3 5];

A shorthand for an array of sequential numbers (with an optional step parameter) is:

a = 5:8;
b = 20:2:24;


Storage Size

To declare a numeric array with a specific storage size, try:

y = uint64(10);

These declaration functions include:

  • double()

  • single()

  • int8()

  • int16()

  • int32()

  • int64()

  • uint8()

  • uint16()

  • uint32()

  • uint64()


Type Casting

The cast function is used to change the storage size of a numeric array. Try:

b = cast(a,"uint8");

The second argument must be one of:

  • "single"

  • "double"

  • "int8"

  • "int16"

  • "int32"

  • "int64"

  • "uint8"

  • "uint16"

  • "uint32"

  • "uint64"

  • "logical"

  • "char"


Character Array

Character arrays store a sequence of characters. They are declared like:

c = 'Hello World';


String

All string variables are arrays. Colloquially, a string array with a single element is called a string scalar.

str = "Greetings friend"
str = ["Greetings friend" "Hello, world"]

To convert a numeric array into a string array, try:

>> str = string([1 24 356]);

str = 1x3 string

   "1"          "24"          "356"


Symbolic Variable

Symbolic variables are created like:

% Declaring symbolic variables.
syms x y;

% Defining symbolic expressions.
f = (x^2 + y^2);

% Defining symbolic functions.
f(x,y) = (x^2 + y^2);

Symbolic functions can then be evaluated for input values.

Symbolic expressions are very similar, but can be used to define a surface to plot or to solve a system.

% Define a quadratic equation.
f = a*x^2 + b*x + c

% Solve for roots of a quadratic equation.
x_0 = solve(f == 0, x);


Function Handle

Function handles are created like:

% Declaring symbolic variables needed by the function handle.
syms x y z;

f = @(x,y,z) (x.^2 + y.^2 + z.^2);


CategoryRicottone

MATLAB/DataTypes (last edited 2025-12-17 19:52:15 by DominicRicottone)