matlab怎麼做膠囊?

時間 2021-06-22 07:18:45

1樓:野生學渣

% Motion of a capsule.

% % Author: AdamTurner, 2021.05.

% Written in MATLAB R2018a.

clear

all;

close

all;

clc;

% ----- Initial Conditions ----- %% Initial position

xc0=

0.000

;yc0

=0.000

;zc0

=0.900

;% Initial orientationphi0

=0.450*pi

;theta0

=0.750*pi

;% ----- Parameters ----- %globalLr

m1m2gdt

;L=0.100;r

=0.100;m1

=0.010;m2

=0.010;g

=9.80665;dt

=1.000e-2

;% ----- Mesh of Capsule ----- %s1=

linspace

(0.000

,0.500*pi

,6).'

;s2=linspace(-

pi,pi,

21).';

[s1,s2

]=meshgrid(s1

,s2);xCapsule=r

*sin(s1

).*cos(

s2);

yCapsule=r

*sin(s1

).*sin(

s2);

zCapsule=r

*cos(s1

);xCapsule=[

xCapsule

,xCapsule

(:,end

),xCapsule

(:,end

),fliplr

(xCapsule

)];yCapsule=[

yCapsule

,yCapsule

(:,end

),yCapsule

(:,end

),fliplr

(yCapsule

)];zCapsule=[

0.500*L

+zCapsule

,zeros(21

,2),-

0.500*L

-fliplr

(zCapsule

)];[

nS2,

nS1]

=size

(zCapsule

);colorCapsule

=zeros

(nS2

,nS1,3

);colorCapsule

(:,1:7

,1)=

1;colorCapsule

(:,8:14

,3)=

1;% ----- Solve ------ %Q0=[xc0

+0.500*L

*sin

(theta0)*

cos(

phi0

);...

yc0+

0.500*L

*sin

(theta0)*

sin(

phi0

);...

zc0+

0.500*L

*cos

(theta0

);...

xc0-

0.500*L

*sin

(theta0)*

cos(

phi0

);...

yc0-

0.500*L

*sin

(theta0)*

sin(

phi0

);...

zc0-

0.500*L

*cos

(theta0

);...

0.000

;...

0.000

;...

0.000

;...

0.000

;...

0.000

;...

0.000

];tSpan=(

0.000:dt

:10.000);[

t,Q]

=...

ode15s

(@KineticEq

,tSpan,Q0

,...

struct

('RelTol'

,1.000e-5

,...

'AbsTol'

,1.000e-5

,...

'MaxStep'

,1.000e-3

,...

'InitialStep'

,1.000e-3

));[x1,

y1,z1,

x2,y2,

z2,u1,

v1,w1,

u2,v2,

w2]=ParseQ(Q

);hFigure

=figure

();hAxes

=...

axes

(hFigure

,...

'Box'

,'on'

,'BoxStyle'

,'full'

,...

'NextPlot'

,'add'

,...

'XGrid'

,'on'

,'YGrid'

,'on'

,'ZGrid'

,'on'

,...

'XLimMode'

,'manual'

,'XLim',[

-0.500

,0.500

],...

'YLimMode'

,'manual'

,'YLim',[

-0.500

,0.500

],...

'ZLimMode'

,'manual'

,'ZLim',[

0.000

,1.000

]);view([-

30.000

,30.000

]);xlabel

(hAxes

,'$x$'

,'Interpreter'

,'latex'

);ylabel

(hAxes

,'$y$'

,'Interpreter'

,'latex'

);zlabel

(hAxes

,'$z$'

,'Interpreter'

,'latex'

);nFrame

=numel(t

);forii=

1:nFrame

ozCapsule=[

x1(ii)

-x2(ii

);y1(ii

)-y2(

ii);z1(

ii)-z2

(ii)];ozCapsule

=ozCapsule

/sqrt

(ozCapsule.'

*ozCapsule

);oxCapsule

=cross

(ozCapsule,[

0.000

;0.000

;1.000

]);oxCapsuleM

=sqrt

(oxCapsule.'

*oxCapsule

);if

oxCapsuleM

<=eps

oxCapsule=[

1.000

;0.000

;0.000

];oyCapsule=[

0.000

;1.000

;0.000

];ozCapsule=[

0.000

;0.000

;1.000

];else

oxCapsule

=oxCapsule

/oxCapsuleM

;oyCapsule

=cross

(ozCapsule

,oxCapsule

);end

% /* if oxCapsuleM <= eps */xyzCapsule

=...

[oxCapsule

,oyCapsule

,ozCapsule

]...*[

xCapsule

(:),

yCapsule

(:),

zCapsule

(:)].';

xyzCapsule(1

,:)=xyzCapsule(1

,:)+0.500*(

x1(ii)

+x2(ii

));xyzCapsule(2

,:)=xyzCapsule(2

,:)+0.500*(

y1(ii)

+y2(ii

));xyzCapsule(3

,:)=xyzCapsule(3

,:)+0.500*(

z1(ii)

+z2(ii

));xxCapsule

=reshape

(xyzCapsule(1

,:).',

nS2,

nS1);

yyCapsule

=reshape

(xyzCapsule(2

,:).',

nS2,

nS1);

zzCapsule

=reshape

(xyzCapsule(3

,:).',

nS2,

nS1);

ifii~=1

hSurfCapsule

.XData

=xxCapsule

;hSurfCapsule

.YData

=yyCapsule

;hSurfCapsule

.ZData

=zzCapsule

;else

hSurfCapsule

=...

surf

(xxCapsule

,yyCapsule

,zzCapsule

,colorCapsule

);end

% /* if ii ~= 1 */

currentFrame

=getframe

(hFigure);[

colorIndex

,colorMap]=

rgb2ind

(currentFrame

.cdata,32

);if

ii~=

1imwrite

(colorIndex

,colorMap

,'Capsule.GIF'

,...

'WriteMode',,

'DelayTime'

,0.050

);else

imwrite

(colorIndex

,colorMap

,'Capsule.GIF'

,'Loopcount'

,Inf

,...

'WriteMode'

,'overwrite'

,'DelayTime'

,0.050

);end

% /* if ii ~= 1 */

end% /* for ii */

% ----- Function(s) ----- %function

dQ =

KineticEq

(t, Q)

globalLr

m1m2gdt

;[x1,

y1,z1,

x2,y2,

z2,u1,

v1,w1,

u2,v2,

w2]=ParseQ(Q

);M=diag

([m1

*ones(3

,1);m2

*ones(3

,1)]);

PhiQ

=PHI_Q(t

,Q);contactFrameBottom

=...

[1.000

,0.000

,0.000

;...

0.000

,1.000

,0.000

;...

0.000

,0.000

,1.000

];contactFrameLeft

=...

[0.000

,0.000

,1.000

;...

1.000

,0.000

,0.000

;...

0.000

,1.000

,0.000

];contactFrameRight

=...

[0.000

,0.000,-

1.000

;...

-1.000

,0.000

,0.000

;...

0.000

,1.000

,0.000

];contactFrameFront

=...[-

1.000

,0.000

,0.000

;...

0.000

,0.000

,1.000

;...

0.000

,1.000

,0.000

];contactFrameBack

=...

[1.000

,0.000

,0.000

;...

0.000

,0.000,-

1.000

;...

0.000

,1.000

,0.000];f

=[ContactForce(x1

,y1,z1

-r,u1

,v1,w1

,contactFrameBottom

);...

ContactForce(x2

,y2,z2

-r,u2

,v2,w2

,contactFrameBottom

)]...+[

ContactForce(x1

+0.500-r

,y1,z1

,u1,v1

,w1,contactFrameLeft

);...

ContactForce(x2

+0.500-r

,y2,z2

,u2,v2

,w2,contactFrameLeft

)]...+[

ContactForce(x1

-0.500+r

,y1,z1

,u1,v1

,w1,contactFrameRight

);...

ContactForce(x2

-0.500+r

,y2,z2

,u2,v2

,w2,contactFrameRight

)]...+[

ContactForce(x1

,y1+0.500-r

,z1,u1

,v1,w1

,contactFrameFront

);...

ContactForce(x2

,y2+0.500-r

,z2,u2

,v2,w2

,contactFrameFront

)]...+[

ContactForce(x1

,y1-0.500+r

,z1,u1

,v1,w1

,contactFrameBack

);...

ContactForce(x2

,y2-0.500+r

,z2,u2

,v2,w2

,contactFrameBack

)]...+[

0.000

;0.000;-

m1*g;

0.000

;0.000;-

m2*g];

dq=[u1

;v1;w1

;u2;v2

;w2];Phi

=PHI(t

,Q);PhiT

=PHI_T(t

,Q);PhiQQ

=PHI_QQ(t

,Q);PhiQT

=PHI_QT(t

,Q);PhiTT

=PHI_TT(t

,Q);alpha

=1.000e3

;beta

=1.000e3

;gamma=(

-dq.'

*PhiQQ*dq

-2*PhiQT*dq

-PhiTT

)...-2

*alpha*(

PhiQ*dq

+PhiT)-

beta

*beta

*Phi

;ddq=[

M,PhiQ.'

;PhiQ

,0.000]\

[f;gamma

];dQ=[

dq;ddq(1:

6)];

end% /* KineticEq */

function

varargout =

ParseQ

(Q)[~,

nColumn]=

size(Q

);if

nColumn==1

Q=Q.

';end% /* if nColumn == 1 */x1=Q(:,1);

y1=Q(:,2);

z1=Q(:,3);

x2=Q(:,4);

y2=Q(:,5);

z2=Q(:,6);

u1=Q(:,7);

v1=Q(:,8);

w1=Q(:,9);

u2=Q(:,

10);v2=

Q(:,

11);w2=

Q(:,

12);

varargout=;

end% /* ParseQ */

function

Phi =

PHI(t, Q)

globalL;

[x1,y1

,z1,x2

,y2,z2

,~,~

,~,~

,~,~

]=ParseQ(Q

);deltaQ=[

x1;y1;

z1]-[

x2;y2;

z2];

Phi=

deltaQ.'

*deltaQ-L

*L;end

% /* PHI */

function

PhiQ =

PHI_Q

(t, Q)[x1

,y1,z1

,x2,y2

,z2,~

,~,~

,~,~

,~]=

ParseQ(Q

);deltaQ=[

x1;y1;

z1]-[

x2;y2;

z2];

PhiQ=[

2*deltaQ;-

2*deltaQ].'

;end

% /* PHI_Q */

function

PhiT =

PHI_T

(t, Q)

PhiT

=0.000

;end

% /* PHI_T */

function

PhiQQ =

PHI_QQ

(t, Q)

PhiQQ

=...

[2.000

*eye(3

,3),-

2.000

*eye(3

,3);...

-2.000

*eye(3

,3),2.000

*eye(3

,3)];end

% /* PHI_QQ */

function

PhiQT =

PHI_QT

(t, Q)

PhiQT

=zeros(1

,6);end

% /* PHI_QT */

function

PhiTT =

PHI_TT

(t, Q)

PhiTT

=0.000

;end

% /* PHI_TT */

function

y =Step3

(x, x1, y1, x2, y2)xi=2.000*(

x-0.500*(

x1+x2))/(

x2-x1);

ifxi

<=-1.000y=

-1.000

;else

ifxi

>=1.000y=

1.000

;elsey=

-0.500*xi

*(xi*

xi-3.000

);end

% /* if xi >= 1.000 */end% /* if xi <= -1.000 */y=0.500*(

y1+y2)

+0.500*y

*(y2-

y1);

end% /* Step3 */

function

f =Impact

(x, v, x1, k, e, cm, d)ifx>=x1

f=0.000

;elsef=

k*(x1

-x)^e-

Step3(x

,x1-d

,cm,x1

,0.000)*

v;f=

max(f,

0.000

);end

% /* if x >= x1 */

end% /* Impact */

function

mu =

FrictionCoefficient

(v, mus, mud)ifv

<=-0.000100mu=

Step3(v

,-0.000150,-

mud,

-0.000100,-

mus);

elseifv

<=0.000100mu=

Step3(v

,-0.000100,-

mus,

0.000100

,mus

);elsemu=

Step3(v

,0.000100

,mus

,0.000150

,mud

);end

% /* if v <= 0.000100 */end% /* if v <= -0.000100 */end% /* FrictionCoefficient */function

f =ContactForce

(x, y, z, u, v, w, contactFrame)r=[x;y

;z];dr=[

u;v;

w];r=

contactFrame.'

*r;dr

=contactFrame.'

*dr;x

=r(1

);y=r

(2);z

=r(3

);u=dr

(1);v

=dr(2

);w=dr

(3);N

=Impact(z

,w,0.000

,1.000e3

,1.000

,1.000e-1

,1.000e-4

);if

N>0.000

vAngle

=angle(u

+v*1

i);vMag

=abs(u

+v*1

i);mu=

FrictionCoefficient

(vMag

,0.200

,0.150);T

=-mu*

N;f=

[T*cos

(vAngle);T

*sin

(vAngle);N

];elsef=

[0.000

;0.000

;0.000

];end

% /* if N > 0.000 */f=contactFrame*f

;end

% /* ContactForce */

怎麼做才能脫單,怎麼做啊?

嗯.我也是來蹲答案的.不過.想了一下,我想我應該主動一點.不然真的活該我單身.如果有四川的1990年到1994年的男孩子.呃.不妨我們認識一下. 獨沐春寒 1.你要學會喜歡乙個人!做到這一點說明你有脫單的渴求。2.你要學會讓乙個人喜歡你!能做到這點,那麼恭喜你。只要你要求不太高,脫單也就是分分鐘的事...

膠囊咖啡機做500ml拿鐵要用幾個膠囊

家用咖啡機指南 膠囊咖啡機的長美式是110ml,濃縮是40ml 內 膠囊咖啡是5g左右咖啡粉,和商用咖啡機不大一樣,已經很大限度上壓榨了這個體量的咖啡萃取效果,商用機是8 10g單份濃縮,做拿鐵大杯大部分是17 19g的雙份濃縮,出36ml 上下 奶的話在160 200ml,打發後到240 300m...

洋蔥做冷盤怎麼做?

多啦A夢 清爽冷盤分類 洋蔥1 2個,芹菜2根。辣椒1個,蒜末1小匙,香菜適量,番茄醬1大匙,甜辣醬,醬油,糖各1小匙,菠蘿罐頭汁,檸檬汁各1大匙。1 洋蔥切絲,芹菜切段用少量鹽稍醃,辣椒切絲,香菜切段,菠蘿切小片。2 將洋蔥 芹菜 辣椒 蒜末 菠蘿加入調味料一起攪拌,最後再加入香菜拌勻,即可盛盤上...