Empty plot returning when I try to graph

2 Ansichten (letzte 30 Tage)
Natali Petani
Natali Petani am 1 Dez. 2022
Bearbeitet: Kevin Holly am 1 Dez. 2022
funciton code
function G = sigmayytheta0(rr) %why did we even need sigma_0 in the first place..?
K = 0.5605;
G = (K/sqrt(2*pi*rr)); %when theta = 0, everything including theta simplifies to 1
end
script code
%sigmayy along theta = 0 degrees
for i = 1:1000;
for j = 1:1000;
x = i/1000;
y = (j-500)/1000;
xtip = x - .1;
rr = sqrt(xtip^2+(y^2));
M = sigmayytheta0(rr);
hold on
end
end
figure(2)
plot(rr,M, "--");
hold off
xlabel('r')
ylabel('sigmayy')
title('Sigmayy versus r at theta = 0');

Antworten (3)

Kevin Holly
Kevin Holly am 1 Dez. 2022
Bearbeitet: Kevin Holly am 1 Dez. 2022
%sigmayy along theta = 0 degrees
for ii = 1:10;
for jj = 1:10;
x = ii/1000;
y = (jj-500)/1000;
xtip = x - .1;
rr(ii,jj,:) = sqrt(xtip^2+(y^2));
M(ii,jj) = sigmayytheta0(rr(ii,jj));
figure(1)
scatter(rr(ii,jj),M(ii,jj),'.b');
hold on
end
end
hold off
xlabel('r')
ylabel('sigmayy')
title('Sigmayy versus r at theta = 0');
figure(2)
plot(rr,M, "--");
% hold off - remove this hold off
xlabel('r')
ylabel('sigmayy')
title('Sigmayy versus r at theta = 0');
function G = sigmayytheta0(rr) %why did we even need sigma_0 in the first place..?
K = 0.5605;
G = (K/sqrt(2*pi*rr)); %when theta = 0, everything including theta simplifies to 1
end

Walter Roberson
Walter Roberson am 1 Dez. 2022
M = sigmayytheta0(rr);
Every iteration in i and j, you are overwriting all of M. At the end, your M will be a scalar.
You should be storing into something indexed with i and j. Likewise with rr
plot(rr,M, "--");
If you assign to rr and M indexed by i and j, you are going to end up with a 2D array, but plot() is for drawing lines. Do you want to draw a scatter plot? Perhaps you want to draw a contour plot? Or a surface plot?
Note that there will be a number of different locations that come out to the same rr value. You are calculating a radius from i = 10, j = 500 and that is going to be radially symmetric.

David Hill
David Hill am 1 Dez. 2022
[i,j]=meshgrid(1:1000);
xtip=i/1000-.1;
y=(j-500)/1000;
rr=hypot(xtip,y);
K=.5605;
M=K./(sqrt(2*pi*rr));
plot(rr,M, "--");
xlabel('r')
ylabel('sigmayy')
title('Sigmayy versus r at theta = 0');

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by