Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Aaron Erhardt
Cheatsheets
Commits
c97b2866
Commit
c97b2866
authored
May 16, 2021
by
Aaron Erhardt
Browse files
Add 3D-plot and differential equations to Matlab
Signed-off-by:
Aaron Erhardt
<
aaron.erhardt@t-online.de
>
parent
f7921b9c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Matlab/Matlab.md
View file @
c97b2866
...
...
@@ -519,6 +519,22 @@ handle = subplot(2, 3, 1); % select first plot
handle
.
Children
(
1
)
.
LineWidth
=
2
;
% get line from handle and change width
```
## 3-dimensional
### 3D-plot
```
matlab
plot3
(
x
,
y
,
z
);
```
### Meshgrid
```
matlab
% Grids are simply specified by matrices of coordinates
[
X
Y
]
=
meshgrid
(
x
,
y
,
z
);
% Generate grid
mesh
(
X
,
Y
)
% Plot mesh
mesh
(
X
,
Y
,
Z
)
% Plot mesh with Z coordinate
```
# Functions
...
...
@@ -624,6 +640,42 @@ id = @(is,ud)is*exp(ud/0.05) % diode current
is
=
lsqcurvefit
(
id
,
1e-10
,
u
,
i
);
% find ideal value for is to fit measured values u and i
```
## Differential equations
### First order
```
matlab
% transform the equation so that u' is separated
du
=
@
(
t
,
u
)
-
u
/
0.1
;
% u' = -u/0.1
U0
=
3
;
% start value
tspan
=
[
0
0.5
];
% time span
[
t
u
]
=
ode45
(
du
,
tspan
,
U0
);
% calculate values
```
### Higher order
```
matlab
% transform the equation so that y' = y1' and y'' = y2' are separated
% y1' = y2 y2' = sin(100*t) - y1 - y2
dy
=
@
(
t
,
y
)
[
y
(
2
)
;
sin
(
100
*
t
)
-
y
(
1
)
-
y
(
2
)
];
% c)
[
t
y
]
=
ode45
(
dy
,
[
0
1
],
[
1
;
0
]);
% start at y1 = 1 and y2 = 0
```
### Options
```
matlab
opts
=
odeset
(
'absTol'
,
0.05
);
% set absolute error tolerance
[
t
y
]
=
ode45
(
@
pendfun
,
tspan
,
yNull
,
opts
);
```
### Other solving algorithms
```
matlab
ode23s
%
```
# Control structures
## for-loop
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment