Welcome to ModSimPy Documentation
This is the documentation for the Modeling and Simulation in Python library.
Links
- GitHub Repository - Source code and issues
- Online Book - The full textbook
API Reference
Params
Bases: SettableNamespace
Contains system parameters and their values.
Takes keyword arguments and stores them as attributes.
Source code in modsim/modsim.py
764 765 766 767 768 769 |
|
SettableNamespace
Bases: SimpleNamespace
Contains a collection of parameters.
Used to make a System object.
Takes keyword arguments and stores them as attributes.
Source code in modsim/modsim.py
664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 |
|
__init__(namespace=None, **kwargs)
Initialize a SettableNamespace.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
namespace
|
SettableNamespace
|
Namespace to copy. Defaults to None. |
None
|
**kwargs
|
Keyword arguments to store as attributes. |
{}
|
Source code in modsim/modsim.py
671 672 673 674 675 676 677 678 679 680 681 |
|
get(name, default=None)
Look up a variable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the variable to look up. |
required |
default
|
any
|
Value returned if |
None
|
Returns:
Name | Type | Description |
---|---|---|
any |
Value of the variable or default. |
Source code in modsim/modsim.py
683 684 685 686 687 688 689 690 691 692 693 694 695 696 |
|
set(**variables)
Make a copy and update the given variables.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**variables
|
Keyword arguments to update. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Params |
New Params object with updated variables. |
Source code in modsim/modsim.py
698 699 700 701 702 703 704 705 706 707 708 709 |
|
System
Bases: SettableNamespace
Contains system parameters and their values.
Takes keyword arguments and stores them as attributes.
Source code in modsim/modsim.py
756 757 758 759 760 761 |
|
State(**variables)
Contains the values of state variables.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**variables
|
Keyword arguments to store as state variables. |
{}
|
Returns:
Type | Description |
---|---|
pd.Series: Series with the state variables. |
Source code in modsim/modsim.py
772 773 774 775 776 777 778 779 780 781 |
|
SweepFrame(*args, **kwargs)
Create a DataFrame that maps from parameter value to SweepSeries.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args
|
Arguments passed to pd.DataFrame. |
()
|
|
**kwargs
|
Keyword arguments passed to pd.DataFrame. |
{}
|
Returns:
Type | Description |
---|---|
pd.DataFrame: DataFrame indexed by parameter value. |
Source code in modsim/modsim.py
887 888 889 890 891 892 893 894 895 896 897 898 |
|
SweepSeries(*args, **kwargs)
Make a pd.Series object to store results from a parameter sweep.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args
|
Arguments passed to pd.Series. |
()
|
|
**kwargs
|
Keyword arguments passed to pd.Series. |
{}
|
Returns:
Type | Description |
---|---|
pd.Series: Series with index name 'Parameter' and name 'Metric'. |
Source code in modsim/modsim.py
832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 |
|
TimeFrame(*args, **kwargs)
Create a DataFrame that maps from time to State.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args
|
Arguments passed to pd.DataFrame. |
()
|
|
**kwargs
|
Keyword arguments passed to pd.DataFrame. |
{}
|
Returns:
Type | Description |
---|---|
pd.DataFrame: DataFrame indexed by time. |
Source code in modsim/modsim.py
873 874 875 876 877 878 879 880 881 882 883 884 |
|
TimeSeries(*args, **kwargs)
Make a pd.Series object to represent a time series.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args
|
Arguments passed to pd.Series. |
()
|
|
**kwargs
|
Keyword arguments passed to pd.Series. |
{}
|
Returns:
Type | Description |
---|---|
pd.Series: Series with index name 'Time' and name 'Quantity'. |
Source code in modsim/modsim.py
810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 |
|
Vector(x, y, z=None, **options)
Create a 2D or 3D vector as a pandas Series.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
float
|
x component. |
required |
y
|
float
|
y component. |
required |
z
|
float
|
z component. Defaults to None. |
None
|
**options
|
Additional keyword arguments for pandas.Series. |
{}
|
Returns:
Type | Description |
---|---|
pd.Series: Series with keys 'x', 'y', and optionally 'z'. |
Source code in modsim/modsim.py
901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 |
|
animate(results, draw_func, *args, interval=None)
Animate results from a simulation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
results
|
TimeFrame
|
Results to animate. |
required |
draw_func
|
callable
|
Function that draws state. |
required |
*args
|
Additional positional arguments passed to draw_func. |
()
|
|
interval
|
float
|
Time between frames in seconds. Defaults to None. |
None
|
Raises:
Type | Description |
---|---|
ValueError
|
If results is not a TimeFrame or draw_func is not callable |
Source code in modsim/modsim.py
1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 |
|
cart2pol(x, y, z=None)
Convert Cartesian coordinates to polar.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
number or sequence
|
x coordinate. |
required |
y
|
number or sequence
|
y coordinate. |
required |
z
|
number or sequence
|
z coordinate. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
tuple |
(theta, rho) or (theta, rho, z). |
Raises:
Type | Description |
---|---|
ValueError
|
If x or y are not numeric or array-like, or if z is provided but not numeric or array-like |
Source code in modsim/modsim.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
|
contour(df, **options)
Makes a contour plot from a DataFrame.
Wrapper for plt.contour https://matplotlib.org/3.1.0/api/_as_gen/matplotlib.pyplot.contour.html
Note: columns and index must be numerical
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
DataFrame to plot. |
required |
**options
|
Additional keyword arguments for plt.contour. |
{}
|
Source code in modsim/modsim.py
588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 |
|
crossings(series, value)
Find the labels where the series passes through a given value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
series
|
Series
|
Series with increasing numerical index. |
required |
value
|
float
|
Value to find crossings for. |
required |
Returns:
Type | Description |
---|---|
np.ndarray: Array of labels where the series crosses the value. |
Source code in modsim/modsim.py
445 446 447 448 449 450 451 452 453 454 455 456 457 |
|
decorate(**options)
Decorate the current axes.
Call decorate with keyword arguments like decorate(title='Title', xlabel='x', ylabel='y')
The keyword arguments can be any of the axis properties https://matplotlib.org/api/axes_api.html
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**options
|
Keyword arguments for axis properties. |
{}
|
Source code in modsim/modsim.py
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 |
|
flip(p=0.5)
Flips a coin with the given probability.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
p
|
float
|
Probability between 0 and 1. |
0.5
|
Returns:
Name | Type | Description |
---|---|---|
bool |
True or False. |
Source code in modsim/modsim.py
81 82 83 84 85 86 87 88 89 90 |
|
gradient(series, **options)
Computes the numerical derivative of a series.
If the elements of series have units, they are dropped.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
series
|
Series
|
Series object. |
required |
**options
|
Additional keyword arguments for np.gradient. |
{}
|
Returns:
Type | Description |
---|---|
pd.Series: Series with the same subclass as the input. |
Raises:
Type | Description |
---|---|
ValueError
|
If series is not a pandas Series |
Source code in modsim/modsim.py
535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 |
|
has_nan(a)
Check whether an array or Series contains any NaNs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
array - like
|
NumPy array or Pandas Series. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
True if any NaNs are present, False otherwise. |
Source code in modsim/modsim.py
460 461 462 463 464 465 466 467 468 469 |
|
interpolate(series, **options)
Create an interpolation function from a Series.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
series
|
Series
|
Series object with strictly increasing index. |
required |
**options
|
Additional keyword arguments for scipy.interpolate.interp1d. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
callable |
Function that maps from the index to the values. |
Raises:
Type | Description |
---|---|
ValueError
|
If the index contains NaNs or is not strictly increasing. |
Source code in modsim/modsim.py
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 |
|
interpolate_inverse(series, **options)
Interpolate the inverse function of a Series.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
series
|
Series
|
Series representing a mapping from a to b. |
required |
**options
|
Additional keyword arguments for scipy.interpolate.interp1d. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
callable |
Interpolation object, can be used as a function from b to a. |
Source code in modsim/modsim.py
520 521 522 523 524 525 526 527 528 529 530 531 532 |
|
is_strictly_increasing(a)
Check whether the elements of an array are strictly increasing.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
array - like
|
NumPy array or Pandas Series. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
True if strictly increasing, False otherwise. |
Source code in modsim/modsim.py
472 473 474 475 476 477 478 479 480 481 |
|
leastsq(error_func, x0, *args, **options)
Find the parameters that yield the best fit for the data using least squares.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
error_func
|
callable
|
Function that computes a sequence of errors. |
required |
x0
|
array - like
|
Initial guess for the best parameters. |
required |
*args
|
Additional positional arguments passed to error_func. |
()
|
|
**options
|
Additional keyword arguments passed to scipy.optimize.leastsq. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
tuple |
(best_params, details) best_params: Best-fit parameters (same type as x0 if possible). details: SimpleNamespace with fit details and success flag. |
Source code in modsim/modsim.py
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 |
|
linrange(start, stop=None, step=1)
Make an array of equally spaced values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start
|
float
|
First value. |
required |
stop
|
float
|
Last value (might be approximate). Defaults to None. |
None
|
step
|
float
|
Difference between elements. Defaults to 1. |
1
|
Returns:
Type | Description |
---|---|
np.ndarray: Array of equally spaced values. |
Source code in modsim/modsim.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
|
magnitude(x)
Return the magnitude of a Quantity or number.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
object
|
Quantity or number. |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
Magnitude as a plain number. |
Source code in modsim/modsim.py
712 713 714 715 716 717 718 719 720 721 |
|
make_series(x, y, **options)
Make a Pandas Series.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
sequence
|
Sequence used as the index. |
required |
y
|
sequence
|
Sequence used as the values. |
required |
**options
|
Additional keyword arguments for pd.Series. |
{}
|
Returns:
Type | Description |
---|---|
pd.Series: Pandas Series. |
Raises:
Type | Description |
---|---|
ValueError
|
If x or y are not array-like or have different lengths |
Source code in modsim/modsim.py
784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 |
|
maximize_scalar(func, *args, **kwargs)
Find the input value that maximizes func
.
Wrapper for https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize_scalar.html
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func
|
callable
|
Function to be maximized. |
required |
*args
|
Additional positional arguments passed to |
()
|
|
**kwargs
|
Additional keyword arguments passed to |
{}
|
Returns:
Name | Type | Description |
---|---|---|
OptimizeResult |
Object containing the maximum and optimization details. |
Raises:
Type | Description |
---|---|
Exception
|
If the optimization does not succeed. |
Source code in modsim/modsim.py
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
|
minimize_scalar(func, *args, **kwargs)
Find the input value that minimizes func
.
Wrapper for https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize_scalar.html
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func
|
callable
|
Function to be minimized. |
required |
*args
|
Additional positional arguments passed to |
()
|
|
**kwargs
|
Additional keyword arguments passed to |
{}
|
Returns:
Name | Type | Description |
---|---|---|
OptimizeResult |
Object containing the minimum and optimization details. |
Raises:
Type | Description |
---|---|
Exception
|
If the optimization does not succeed. |
Source code in modsim/modsim.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
|
plot_segment(A, B, **options)
Plots a line segment between two Vectors.
For 3-D vectors, the z axis is ignored.
Additional options are passed along to plot().
Parameters:
Name | Type | Description | Default |
---|---|---|---|
A
|
Vector
|
First vector. |
required |
B
|
Vector
|
Second vector. |
required |
**options
|
Additional keyword arguments for plt.plot. |
{}
|
Raises:
Type | Description |
---|---|
ValueError
|
If A or B are not Vector objects |
Source code in modsim/modsim.py
1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 |
|
pol2cart(theta, rho, z=None)
Convert polar coordinates to Cartesian.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
theta
|
number or sequence
|
Angle in radians. |
required |
rho
|
number or sequence
|
Radius. |
required |
z
|
number or sequence
|
z coordinate. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
tuple |
(x, y) or (x, y, z). |
Raises:
Type | Description |
---|---|
ValueError
|
If theta or rho are not numeric or array-like, or if z is provided but not numeric or array-like |
Source code in modsim/modsim.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
|
remove_from_legend(bad_labels)
Remove specified labels from the current plot legend.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bad_labels
|
list
|
Sequence of label strings to remove from the legend. |
required |
Source code in modsim/modsim.py
648 649 650 651 652 653 654 655 656 657 658 659 660 661 |
|
remove_units(namespace)
Remove units from the values in a Namespace (top-level only).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
namespace
|
object
|
Namespace with attributes. |
required |
Returns:
Name | Type | Description |
---|---|---|
object |
New Namespace object with units removed from values. |
Source code in modsim/modsim.py
724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 |
|
remove_units_series(series)
Remove units from the values in a Series (top-level only).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
series
|
Series
|
Series with possible units. |
required |
Returns:
Type | Description |
---|---|
pd.Series: New Series object with units removed from values. |
Source code in modsim/modsim.py
741 742 743 744 745 746 747 748 749 750 751 752 753 |
|
root_scalar(func, *args, **kwargs)
Find the input value that is a root of func
.
Wrapper for https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.root_scalar.html
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func
|
callable
|
Function to find a root of. |
required |
*args
|
Additional positional arguments passed to |
()
|
|
**kwargs
|
Additional keyword arguments passed to |
{}
|
Returns:
Name | Type | Description |
---|---|---|
RootResults |
Object containing the root and convergence information. |
Raises:
Type | Description |
---|---|
ValueError
|
If the solver does not converge. |
Source code in modsim/modsim.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
|
run_solve_ivp(system, slope_func, **options)
Compute a numerical solution to a differential equation using solve_ivp.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
system
|
System
|
System object containing 'init', 't_end', and optionally 't_0'. |
required |
slope_func
|
callable
|
Function that computes slopes. |
required |
**options
|
Additional keyword arguments for scipy.integrate.solve_ivp. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
tuple |
(TimeFrame of results, details from solve_ivp) |
Raises:
Type | Description |
---|---|
ValueError
|
If required system attributes are missing or if the solver fails. |
Source code in modsim/modsim.py
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 |
|
savefig(filename, **options)
Save the current figure.
Keyword arguments are passed along to plt.savefig
https://matplotlib.org/api/_as_gen/matplotlib.pyplot.savefig.html
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename
|
str
|
Name of the file to save the figure to. |
required |
**options
|
Additional keyword arguments for plt.savefig. |
{}
|
Source code in modsim/modsim.py
609 610 611 612 613 614 615 616 617 618 619 620 621 |
|
scalar_proj(v, w)
Returns the scalar projection of v onto w.
Which is the magnitude of the projection of v onto w.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
v
|
array - like
|
Vector to project. |
required |
w
|
array - like
|
Vector to project onto. |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
Scalar projection of v onto w. |
Source code in modsim/modsim.py
1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 |
|
show(obj)
Display a Series or Namespace as a DataFrame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
object
|
Series or Namespace to display. |
required |
Returns:
Type | Description |
---|---|
pd.DataFrame: DataFrame representation of the object. |
Source code in modsim/modsim.py
854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 |
|
source_code(obj)
Print the source code for a given object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
object
|
Function or method object to print source for. |
required |
Source code in modsim/modsim.py
558 559 560 561 562 563 564 |
|
underride(d, **options)
Add key-value pairs to d only if key is not in d.
If d is None, create a new dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
d
|
dict
|
Dictionary to update. |
required |
**options
|
Keyword arguments to add to d. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
dict |
Updated dictionary. |
Source code in modsim/modsim.py
567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 |
|
validate_array_like(value, name)
Validate that a value is array-like.
Source code in modsim/modsim.py
71 72 73 74 |
|
validate_numeric(value, name)
Validate that a value is numeric.
Source code in modsim/modsim.py
66 67 68 69 |
|
validate_positive(value, name)
Validate that a value is positive.
Source code in modsim/modsim.py
76 77 78 79 |
|
vector_angle(v)
Angle between v and the positive x axis.
Only works with 2-D vectors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
v
|
array - like
|
2-D vector. |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
Angle in radians. |
Raises:
Type | Description |
---|---|
ValueError
|
If v is not array-like or is not 2D |
Source code in modsim/modsim.py
958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 |
|
vector_cross(v, w)
Cross product of v and w.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
v
|
array - like
|
First vector. |
required |
w
|
array - like
|
Second vector. |
required |
Returns:
Type | Description |
---|---|
array-like: Cross product of v and w. |
Raises:
Type | Description |
---|---|
ValueError
|
If v or w are not array-like, or not both 2D or 3D, or not same length |
Source code in modsim/modsim.py
1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 |
|
vector_diff_angle(v, w)
Angular difference between two vectors, in radians.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
v
|
array - like
|
First vector. |
required |
w
|
array - like
|
Second vector. |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
Angular difference in radians. |
Raises:
Type | Description |
---|---|
ValueError
|
If v or w are not array-like or not same length |
NotImplementedError
|
If the vectors are not 2-D. |
Source code in modsim/modsim.py
1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 |
|
vector_dist(v, w)
Euclidean distance from v to w, with units.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
v
|
array - like
|
First vector. |
required |
w
|
array - like
|
Second vector. |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
Euclidean distance from v to w. |
Raises:
Type | Description |
---|---|
ValueError
|
If v or w are not array-like or not same length |
Source code in modsim/modsim.py
1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 |
|
vector_dot(v, w)
Dot product of v and w.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
v
|
array - like
|
First vector. |
required |
w
|
array - like
|
Second vector. |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
Dot product of v and w. |
Raises:
Type | Description |
---|---|
ValueError
|
If v or w are not array-like or have different lengths |
Source code in modsim/modsim.py
1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 |
|
vector_hat(v)
Unit vector in the direction of v.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
v
|
array - like
|
Vector. |
required |
Returns:
Type | Description |
---|---|
array-like: Unit vector in the direction of v. |
Raises:
Type | Description |
---|---|
ValueError
|
If v is not array-like |
Source code in modsim/modsim.py
995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 |
|
vector_mag(v)
Vector magnitude.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
v
|
array - like
|
Vector. |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
Magnitude of the vector. |
Raises:
Type | Description |
---|---|
ValueError
|
If v is not array-like or is empty |
Source code in modsim/modsim.py
922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 |
|
vector_mag2(v)
Vector magnitude squared.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
v
|
array - like
|
Vector. |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
Magnitude squared of the vector. |
Raises:
Type | Description |
---|---|
ValueError
|
If v is not array-like or is empty |
Source code in modsim/modsim.py
940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 |
|
vector_perp(v)
Perpendicular Vector (rotated left).
Only works with 2-D Vectors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
v
|
array - like
|
2-D vector. |
required |
Returns:
Name | Type | Description |
---|---|---|
Vector |
Perpendicular vector. |
Raises:
Type | Description |
---|---|
ValueError
|
If v is not array-like or is not 2D |
Source code in modsim/modsim.py
1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 |
|
vector_polar(v)
Vector magnitude and angle.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
v
|
array - like
|
Vector. |
required |
Returns:
Name | Type | Description |
---|---|---|
tuple |
(magnitude, angle in radians). |
Raises:
Type | Description |
---|---|
ValueError
|
If v is not array-like |
Source code in modsim/modsim.py
979 980 981 982 983 984 985 986 987 988 989 990 991 992 |
|
vector_proj(v, w)
Projection of v onto w.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
v
|
array - like
|
Vector to project. |
required |
w
|
array - like
|
Vector to project onto. |
required |
Returns:
Type | Description |
---|---|
array-like: Projection of v onto w. |
Raises:
Type | Description |
---|---|
ValueError
|
If v or w are not array-like or not same length |
Source code in modsim/modsim.py
1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 |
|