Skip to content

something #2

Merged
merged 41 commits into from
Feb 14, 2017
Merged
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
3f723f4
lecture 2 notes
rcc02007 Jan 19, 2017
e6166c3
HW 1 add collaborator
rcc02007 Jan 19, 2017
88f2c75
office hours updated
rcc02007 Jan 19, 2017
afbd43c
welcome to Peiyu
rcc02007 Jan 24, 2017
3f67614
added lectures 3 and 4
rcc02007 Jan 26, 2017
8785ec4
added temporary_file to test github desktop
rcc02007 Jan 26, 2017
225c502
Delete temporary_file.txt
rcc02007 Jan 26, 2017
bd5e59d
updated lecture_04
rcc02007 Jan 26, 2017
ae4d20e
Merge branch 'master' of https://github.uconn.edu/rcc02007/ME3255S2017
rcc02007 Jan 26, 2017
10234c8
remove old plot pngs
rcc02007 Jan 26, 2017
a623138
add pdf of lecture_4
rcc02007 Jan 26, 2017
e5b6204
added lecture_05
rcc02007 Jan 26, 2017
e44a490
added lecture_05
rcc02007 Jan 26, 2017
af7ae19
added HW 2
rcc02007 Jan 27, 2017
7696985
format HW2
rcc02007 Jan 27, 2017
7f93380
fix typo in HW2
rcc02007 Jan 27, 2017
a498831
add HW2 figure
rcc02007 Jan 28, 2017
9cff604
Merge branch 'master' of https://github.uconn.edu/rcc02007/ME3255S2017
rcc02007 Jan 28, 2017
490943d
add HW2 figure png
rcc02007 Jan 28, 2017
0156322
add HW2 figure png
rcc02007 Jan 28, 2017
f8b20da
Update README.md
rcc02007 Jan 28, 2017
ae2b934
Update syllabus tools used
rcc02007 Jan 28, 2017
436a6ba
Update syllabus tools used and format
rcc02007 Jan 28, 2017
ab77768
Add matlab link
rcc02007 Jan 28, 2017
517b20c
Add links for octave and github
rcc02007 Jan 28, 2017
561666b
Peiyu's office hour is updated.
pez16103 Jan 30, 2017
67cefad
updated lecture 05
rcc02007 Jan 31, 2017
db85c52
Merge branch 'master' of https://github.uconn.edu/rcc02007/ME3255S2017
rcc02007 Jan 31, 2017
908bbf1
updated lecture 06
rcc02007 Feb 2, 2017
2ce5ca3
updated lecture 07
rcc02007 Feb 7, 2017
1282935
updated lecture 07 output
rcc02007 Feb 7, 2017
3bfd22a
updated lecture 07 pdf and markdown
rcc02007 Feb 7, 2017
3519f1b
added HW3
rcc02007 Feb 8, 2017
6e10962
added HW3
rcc02007 Feb 8, 2017
889acf4
update HW3
rcc02007 Feb 13, 2017
4b1d857
update HW3
rcc02007 Feb 13, 2017
593b1de
updated HW3 1d
rcc02007 Feb 13, 2017
59658f7
Delete �Y
rcc02007 Feb 13, 2017
e5f170b
Delete �40
rcc02007 Feb 13, 2017
5128cfd
update lecture 08
rcc02007 Feb 14, 2017
9e7d607
Merge branch 'master' of https://github.uconn.edu/rcc02007/ME3255S2017
rcc02007 Feb 14, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added lectures 3 and 4
rcc02007 committed Jan 26, 2017
commit 3f676141d42c2570d286828a51a0a990d9464b88
5 changes: 5 additions & 0 deletions lecture_03/file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
computational mechanics
the dog had 4 legs and weighed 10.0 lbs
are you awake?computational mechanics
the dog had 4 legs and weighed 10.0 lbs
are you awake?
6,077 changes: 6,077 additions & 0 deletions lecture_03/lecture_03.ipynb

Large diffs are not rendered by default.

1,447 changes: 1,447 additions & 0 deletions lecture_03/lecture_03.md

Large diffs are not rendered by default.

Binary file added lecture_03/octave-workspace
Binary file not shown.
Binary file added lecture_03/output_58_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
270 changes: 270 additions & 0 deletions lecture_03/output_63_0.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,632 changes: 1,632 additions & 0 deletions lecture_03/output_64_0.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,146 changes: 2,146 additions & 0 deletions lecture_03/output_65_0.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
309 changes: 309 additions & 0 deletions lecture_04/lecture_4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,309 @@


```matlab
## When using the command prompt, anything in your path or working directory can be run either as a script, function or class (to define objects)
```

Error: The input character is not valid in MATLAB statements or expressions.



```matlab
%myscript
```


```matlab
%plot --format svg
```

When using the GUI, your command history is saved, but it is better to save your work either as a script or a function or combination of both

Creating a default graph script: `setdefaults.m`

```matlab
set(0, 'defaultAxesFontSize', 16)
set(0,'defaultTextFontSize',14)
set(0,'defaultLineLineWidth',3)
```


```matlab
set(0, 'defaultAxesFontSize', 16)
set(0,'defaultTextFontSize',14)
set(0,'defaultLineLineWidth',3)
```


```matlab
t_linear=linspace(0,10,100);
plot(t_linear,t_linear.^2)
xlabel('time (s)')
ylabel('displacement (m)')
```


![png](output_5_0.png)


#EOL

## Graphics can be produced with a number of functions

2-D plots, 3-D plots, contour plots, 3D contour plots ...


```matlab
x=linspace(-1,1,21); y=linspace(-1,1,21);
[X,Y]=meshgrid(x,y);
Z=(X.*Y.^3-X.^3.*Y)
```

Z =

Columns 1 through 7

0 0.1710 0.2880 0.3570 0.3840 0.3750 0.3360
-0.1710 0 0.1224 0.2016 0.2430 0.2520 0.2340
-0.2880 -0.1224 0 0.0840 0.1344 0.1560 0.1536
-0.3570 -0.2016 -0.0840 0 0.0546 0.0840 0.0924
-0.3840 -0.2430 -0.1344 -0.0546 0 0.0330 0.0480
-0.3750 -0.2520 -0.1560 -0.0840 -0.0330 0 0.0180
-0.3360 -0.2340 -0.1536 -0.0924 -0.0480 -0.0180 0
-0.2730 -0.1944 -0.1320 -0.0840 -0.0486 -0.0240 -0.0084
-0.1920 -0.1386 -0.0960 -0.0630 -0.0384 -0.0210 -0.0096
-0.0990 -0.0720 -0.0504 -0.0336 -0.0210 -0.0120 -0.0060
0 0 0 0 0 0 0
0.0990 0.0720 0.0504 0.0336 0.0210 0.0120 0.0060
0.1920 0.1386 0.0960 0.0630 0.0384 0.0210 0.0096
0.2730 0.1944 0.1320 0.0840 0.0486 0.0240 0.0084
0.3360 0.2340 0.1536 0.0924 0.0480 0.0180 0.0000
0.3750 0.2520 0.1560 0.0840 0.0330 0 -0.0180
0.3840 0.2430 0.1344 0.0546 -0.0000 -0.0330 -0.0480
0.3570 0.2016 0.0840 0 -0.0546 -0.0840 -0.0924
0.2880 0.1224 0 -0.0840 -0.1344 -0.1560 -0.1536
0.1710 0.0000 -0.1224 -0.2016 -0.2430 -0.2520 -0.2340
0 -0.1710 -0.2880 -0.3570 -0.3840 -0.3750 -0.3360

Columns 8 through 14

0.2730 0.1920 0.0990 0 -0.0990 -0.1920 -0.2730
0.1944 0.1386 0.0720 0 -0.0720 -0.1386 -0.1944
0.1320 0.0960 0.0504 0 -0.0504 -0.0960 -0.1320
0.0840 0.0630 0.0336 0 -0.0336 -0.0630 -0.0840
0.0486 0.0384 0.0210 0 -0.0210 -0.0384 -0.0486
0.0240 0.0210 0.0120 0 -0.0120 -0.0210 -0.0240
0.0084 0.0096 0.0060 0 -0.0060 -0.0096 -0.0084
0 0.0030 0.0024 0 -0.0024 -0.0030 0
-0.0030 0 0.0006 0 -0.0006 0 0.0030
-0.0024 -0.0006 0 0 0.0000 0.0006 0.0024
0 0 0 0 0 0 0
0.0024 0.0006 -0.0000 0 0 -0.0006 -0.0024
0.0030 0 -0.0006 0 0.0006 0 -0.0030
0 -0.0030 -0.0024 0 0.0024 0.0030 0
-0.0084 -0.0096 -0.0060 0 0.0060 0.0096 0.0084
-0.0240 -0.0210 -0.0120 0 0.0120 0.0210 0.0240
-0.0486 -0.0384 -0.0210 0 0.0210 0.0384 0.0486
-0.0840 -0.0630 -0.0336 0 0.0336 0.0630 0.0840
-0.1320 -0.0960 -0.0504 0 0.0504 0.0960 0.1320
-0.1944 -0.1386 -0.0720 0 0.0720 0.1386 0.1944
-0.2730 -0.1920 -0.0990 0 0.0990 0.1920 0.2730

Columns 15 through 21

-0.3360 -0.3750 -0.3840 -0.3570 -0.2880 -0.1710 0
-0.2340 -0.2520 -0.2430 -0.2016 -0.1224 -0.0000 0.1710
-0.1536 -0.1560 -0.1344 -0.0840 0 0.1224 0.2880
-0.0924 -0.0840 -0.0546 0 0.0840 0.2016 0.3570
-0.0480 -0.0330 0.0000 0.0546 0.1344 0.2430 0.3840
-0.0180 0 0.0330 0.0840 0.1560 0.2520 0.3750
-0.0000 0.0180 0.0480 0.0924 0.1536 0.2340 0.3360
0.0084 0.0240 0.0486 0.0840 0.1320 0.1944 0.2730
0.0096 0.0210 0.0384 0.0630 0.0960 0.1386 0.1920
0.0060 0.0120 0.0210 0.0336 0.0504 0.0720 0.0990
0 0 0 0 0 0 0
-0.0060 -0.0120 -0.0210 -0.0336 -0.0504 -0.0720 -0.0990
-0.0096 -0.0210 -0.0384 -0.0630 -0.0960 -0.1386 -0.1920
-0.0084 -0.0240 -0.0486 -0.0840 -0.1320 -0.1944 -0.2730
0 -0.0180 -0.0480 -0.0924 -0.1536 -0.2340 -0.3360
0.0180 0 -0.0330 -0.0840 -0.1560 -0.2520 -0.3750
0.0480 0.0330 0 -0.0546 -0.1344 -0.2430 -0.3840
0.0924 0.0840 0.0546 0 -0.0840 -0.2016 -0.3570
0.1536 0.1560 0.1344 0.0840 0 -0.1224 -0.2880
0.2340 0.2520 0.2430 0.2016 0.1224 0 -0.1710
0.3360 0.3750 0.3840 0.3570 0.2880 0.1710 0



```matlab
contour(X,Y,Z)
```


![png](output_10_0.png)



```matlab
mesh(X,Y,Z)
```


![png](output_11_0.png)



```matlab
pcolor(X,Y,Z)
```


![png](output_12_0.png)


## Functions

So far, everything has been executed as a script, or calling a built-in function. Now we begin building our own functions.

Functions are saved in memory (or better yet) in a folder in your path or current directory

Example of storing function in memory

$f(x,y) = (xy^{3}-x^{3}y)$


```matlab
f= @(x,y) (x.*y.^3-x.^3.*y)
```

f =

@(x,y)(x.*y.^3-x.^3.*y)



```matlab
f(0.1,-0.5)
```

ans =

-0.0120


Here we will save a function called `my_function` as `my_function.m`

```matlab
function [vx,vy] = my_function(x,y,t)
% Help documentation of "my_function"
% This function computes the velocity in the x- and y-directions given
% three vectors of position in x- and y-directions as a function of time
% x = x-position
% y = y-position
% t = time
% output
% vx = velocity in x-direction
% vy = velocity in y-direction
vx=zeros(length(t),1);
vy=zeros(length(t),1);
vx(1:end-1) = diff(x)./diff(t); % calculate vx as delta x/delta t
vy(1:end-1) = diff(y)./diff(t); % calculate vy as delta y/delta t
vx(end) = vx(end-1);
vy(end) = vy(end-1);
end
```


```matlab
help my_function
```

Help documentation of "my_function"
This function computes the velocity in the x- and y-directions given
three vectors of position in x- and y-directions as a function of time
x = x-position
y = y-position
t = time
output
vx = velocity in x-direction
vy = velocity in y-direction



```matlab
t=linspace(0,10,100)';
x=t.^3; % vx = 3*t^2
y=t.^2/2; % vy = t
[vx,vy]=my_function(x,y,t);
```


```matlab
yyaxis left
plot(t(1:10:end),vx(1:10:end),'o',t,3*t.^2)
ylabel('v_{x}')
yyaxis right
plot(t(1:10:end),vy(1:10:end),'s',t, t)
ylabel('v_{y}')
xlabel('time')
```


![png](output_20_0.png)


Now, create a new function that calls 'my_function' called, `my_caller.m`


```matlab
help my_caller
```

Help documentation of "my_caller"
This function computes the acceleration in the x- and y-directions given
three vectors of position in x- and y-directions as a function of time
x = x-position
y = y-position
t = time
output
ax = velocity in x-direction
ay = velocity in y-direction



```matlab
[ax,ay]=my_caller(x,y,t);
```


```matlab
yyaxis left
plot(t(1:10:end),ax(1:10:end),'o',t,6*t)
ylabel('a_{x}')
yyaxis right
plot(t(1:10:end),ay(1:10:end),'s',t, 1*t./t)
ylabel('a_{x}')
xlabel('time')
axis([0,10,0,3])
```


![png](output_24_0.png)



```matlab
diff_match_dims(x,t)
```

Undefined function 'diff_match_dims' for input arguments of type 'double'.



```matlab
```
11 changes: 11 additions & 0 deletions lecture_04/myscript.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
f=100;

for i=1:10
g=i^2;
if f==g
fprintf('we made it\n')
else
fprintf('not yet\n')
end
end

Binary file added lecture_04/output_10_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lecture_04/output_11_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lecture_04/output_12_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lecture_04/output_20_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lecture_04/output_24_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lecture_04/output_5_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.