Need help plotting this

2 次查看(过去 30 天)
I need help plotting this code so that my plot will look like the discontinuous sine waves (bolded black) in the graph posted below the code (for one unit cell). Right now my plot is showing up blank.
clear all;
format long;
im = sqrt(-1);
CellLength = 1;
ibeta = 1;
%Define materal properties
CellLength = 1;
layers = 2;
d = [0.4;0.6];
dTotal = d(1,1)+d(2,1);
xc = [0;0.4];
Ef = 12;
pf = 3;
cf = sqrt(Ef/pf);
Em = 1;
pm = 1;
cm = sqrt(Em/pm);
w = 5;
T1 = [cos(.2*w) (1/(6*w))*sin(.2*w); -6*w*sin(.2*w) cos(.2*w)];
T2 = [cos(.6*w) (1/w)*sin(.6*w); -w*sin(.6*w) cos(.6*w)];
T = T2*T1;
Z1 = 6*w;
Z2 = w;
Z = [Z1;Z2];
%Solve eigenvalue problem for k
[V,D] = eig(T); %D = eigenvalues, %V = eigenvectors
k1 = log(D(1,1))/(im*dTotal);
k2 = log(D(2,2))/(im*dTotal);
k = [k1;k2];
B1 = [1 1;im*30 -im*30];
B2 = [1 1;im*5 -im*5];
C1a = [1 0;0 1];
C2a = [exp(im*k2*0.4) 0;0 exp(-im*k2*0.4)];
a1 = inv(B1)*V(:,1);
a2 = inv(C2a)*inv(B2)*T1*B1*a1;
for x1 = 0:0.1:0.4
C1 = @(x1)([exp(im*k1*x1) 0;0 exp(-im*k1*x1)]);
C1 = C1(x1);
y1 = @(x1)(B1*C1*a1);
y1 = y1(x1);
end
for x2 = 0.4:0.1:1
C2 = @(x2)([exp(im*k2*x2) 0;0 exp(-im*k2*x2)]);
C2 = C2(x2);
y2 = @(x2)(B2*C2*a2);
y2 = y2(x2);
end
plot(x1,real(y1(1,:)))
hold on
plot(x2,real(y2(1,:)))
xlabel('Position, x')
ylabel('Displacement, u')

采纳的回答

Star Strider
Star Strider 2018-4-13
Two related problems are that the ‘y1’ and ‘y2’ functions do not use their arguments in their calculations. (I would also rename them ‘y1f’ and ‘y2f’ to avoid confusion with your ‘y1’ and ‘y2’ vectors.)
What do you want to do in those functions?
  6 个评论
Amanda Lococo
Amanda Lococo 2018-4-15
I will try that then! Thanks again for all of your help!
Star Strider
Star Strider 2018-4-15
As always, my pleasure!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by