why this not works? there is a error "??? Error using ==> times Matrix dimensions must agree." in Sx line. how can i fix and plot the graphic?
1 view (last 30 days)
Show older comments
K = 300;
theta = 0:pi/10:pi/2;
x = 0.02:0.01:0.2;
y = 0.02:0.01:0.2;
[X,Y]=meshgrid(x,y);
r=(sqrt(X.^2+Y.^2));
Sx = (K./(sqrt(2.*pi.*r)).*(cos(theta./2)).*(1-(sin(theta./2).*sin((3.*theta)./2))));
mesh(x,y,Sx) grid on
i try plot the stresses graphic. 0<theta<90 0.02<r<0.2 K=300. x and y horizontal plane ,and the stresses in the vertical plane.and Sx formula i writed the above.
0 Comments
Answers (1)
Guillaume
on 10 Dec 2014
The basic problem is that you're trying to multiply
f1(x, y) = K / sqrt(2*pi*r), with r = sqrt(x.^2+y.^2)
with
f2(theta) = cos(theta/2) .* ...
The former is a 19x19 matrix, the latter a 1x6 vector. So, of course, the matrix dimensions don't agree.
What are you trying to plot, though? Is it Sx(r, theta) or Sx(x, y, theta)?
The first one would be:
r = linspace(0.02, 0.2, 20); %20 values between 0.02 and 0.2
theta = linspace(0, pi/2, 6); %6 values between 0 and pi/2
[r, theta] = meshgrid(r, theta);
Sx = (K./(sqrt(2.*pi.*r)).*(cos(theta./2)).*(1-(sin(theta./2).*sin((3.*theta)./2))));
The second one would be a 3D matrix, you would have to change your meshgrid to ndgrid
[X, Y, theta] = ndgrid(x, y, theta);
4 Comments
Guillaume
on 10 Dec 2014
Ok, I understand now. You want to plot Sx(x,y) but the formula for Sx is based on polar coordinates, so:
K = 300;
[x, y] = meshgrid(linspace(0.02, 0.2, 20));
[r, theta] = cart2pol(x, y);
Sx = (K./(sqrt(2.*pi.*r)).*(cos(theta./2)).*(1-(sin(theta./2).*sin((3.*theta)./2))));
mesh(x, y, Sx)
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!