How do I use eval?
12 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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')
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
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
fprintf('\n ====== Exercise 2.1 a end=======\n\n')
%% principle stresses
fprintf('\n ====== Exercise 2.1 b =======\n\n')
I = [1 0; 0 1];
[V,D] =eig( tau );
V
fprintf('\nEigenvalues: 1= %.1f 2=%.1f\n', diag(D))
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)
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
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);
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 comentarios
the cyclist
el 9 de Feb. de 2024
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.
Respuestas (0)
Ver también
Categorías
Más información sobre Stress and Strain en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!