How do I use eval?

9 次查看(过去 30 天)
Kathleen
Kathleen 2024-2-9
评论: Kathleen 2024-2-9
I have errors using the eval function on line 102 and 110. How do I fix that? Thanks!
clear; clc; close all
%% normal stress
fprintf('\n ====== Exercise 2.1 a=======\n\n')
====== Exercise 2.1 a=======
tau = [-30 -20; -20 -40]; %2D stress tensor (Mpa)
theta = 10;
fhat = [sind(theta) , cosd(theta)];
nhat = [ cosd(theta) , -sind(theta)];
tnhat = tau * nhat.';
tn = nhat * tnhat %normal stress
tn = -23.4611
if 1
figure(1); hold on; grid on; axis equal
x = [ 0 1 ; 1 0];
for th = [ 90 180 -90 -180];
X= [cosd(th) sind(th); -sind(th) cosd(th)];
yp = X * x;
quiver(0,0,yp(1),yp(2),0,'r-');
end
end
%% shear stress
ts = fhat * tnhat
ts = -17.0838
fprintf('\n ====== Exercise 2.1 a end=======\n\n')
====== Exercise 2.1 a end=======
%% principle stresses
fprintf('\n ====== Exercise 2.1 b =======\n\n')
====== Exercise 2.1 b =======
I = [1 0; 0 1];
[V,D] =eig( tau );
V
V = 2×2
0.6154 -0.7882 0.7882 0.6154
fprintf('\nEigenvalues: 1= %.1f 2=%.1f\n', diag(D))
Eigenvalues: 1= -55.6 2=-14.4
eva(1) = atan2d( V(1,1), V(2,1) ); %eigenvec-1 angle +cw w.r.t. North
eva(2) = 180 + atan2d( V(1,2), V(2,2) ); %eigenvec-2 angle +cw w.r.t. North
fprintf('\nEvec angles reckoned +cw w.r.t N: 1= %.1f 2= %.1f (deg) \n\n', eva)
Evec angles reckoned +cw w.r.t N: 1= 38.0 2= 128.0 (deg)
ang = [0:45:360];
figure(2); hold on; grid on; axis equal
for i = 1: length(ang)
x = cosd(ang(i));
y = sind(ang(i));
a1 = atan2d(y,x); % +CCW wrt East (+x-hat)
a2 = atan2d(x,y); % +CW wrt North (+y-hat)
if 0 %this block will use modulus to map angles from -pi/pi to 0-2*pi domain
a1 = mod(a1,360);
a2 = mod(a2,360);
end
fprintf('x/y= (%5.1f %5.1f) a1/a2 =%6.1f %6.1f \n',x,y,a1, a2)
plot([0 x],[0 y],'k-')
tt = compose('a1= %d a2=%d', a1,a2);
text(x,y,tt, 'fontsize',15)
end
x/y= ( 1.0 0.0) a1/a2 = 0.0 90.0 x/y= ( 0.7 0.7) a1/a2 = 45.0 45.0 x/y= ( 0.0 1.0) a1/a2 = 90.0 0.0 x/y= ( -0.7 0.7) a1/a2 = 135.0 -45.0 x/y= ( -1.0 0.0) a1/a2 = 180.0 -90.0 x/y= ( -0.7 -0.7) a1/a2 =-135.0 -135.0 x/y= ( 0.0 -1.0) a1/a2 = -90.0 180.0 x/y= ( 0.7 -0.7) a1/a2 = -45.0 135.0 x/y= ( 1.0 0.0) a1/a2 = 0.0 90.0
figure(3); hold on; grid on
set(0,'DefaultLineLineWidth',5,'DefaultAxesFontSize',12)
theta=10;yy=[-40,30];% x-coordinates of the line passing through the center
x1_fault=tand(theta)*yy; % y-coordinates of the line passing through the
plot(x1_fault, yy,'r--','LineWidth', 2);hold on
nn = 20*nhat; ff= 20*fhat;
quiver(0,0, nn(1), nn(2), 0, 'b-','linewidth',3)
quiver(0,0, ff(1), ff(2), 0, 'g-','linewidth',3)
ee = eval(1,1) * evec(:,1);
Error using eval
Argument must be a text scalar.
quiver(0,0,ee(1,1),ee(2,1),'k-','linewidth',2)
quiver(0,0,evec(1,1)*20,evec(2,1)*20,'m-','linewidth',2)
fprintf('max principle stress axis = %.1f (deg)\n', atand(ee(1)/ee(2)) )
ee = eval(2,2) * evec(:,2); %min principle eigen-vec
quiver(0,0,ee(1),ee(2),'k-','linewidth',2)
quiver(0,0,evec(1,2)*20,evec(2,2)*20,'m-','linewidth',2)
xline(0, 'linewidth',0.5); yline(0, 'linewidth',0.5)
% Set x-axis and y-axis limits
xlim([-40, 30]);
ylim([-40, 30]);
% Set grid intervals to be multiples of 10
set(gca, 'XTick', -40:10:30);
set(gca, 'YTick', -40:10:30);
lgd = legend('','','','','fault','fault normal','fault parallel','eval1*evec-1','evec1', 'eval2*evec-2','evec2');
lgd.FontSize = 15; lgd.Location = 'northwest';
title('Exercise 2.1'); xlabel('x-axis (MPa)'); ylabel('y-axis (MPa)')
fprintf('\n ====== Exercise 2.1 b end=======\n\n')
  3 个评论
the cyclist
the cyclist 2024-2-9
I can't figure out how to fix your code. But I don't think you want the MATLAB eval function, which is completely unrelated to what you are doing.
It looks like whoever wrote this code -- you? -- intended to calculate the eigenvalue (eval?) and eigenvector (evec?), and do something with them.
Earlier in the code, I see a variable named eva (not eval). And I see ee. I just can't quite figure out what is intended.
But since this is homework, I guess that's your job, not mine.
Kathleen
Kathleen 2024-2-9
yeah, I wrote the code from scratch. I am horrible with mathlab but I try my best. It had to be eva and not eval. Stupid me, I figured it out. Thanks!

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Stress and Strain 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by