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)
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.

Answers (1)

Guillaume
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
Bugra
Bugra on 10 Dec 2014
Edited: Bugra on 10 Dec 2014
i try to plot the coordinates x and y horizontal plane and the stresses in the vertical direction. but i have theta and r values. in formula there are r and theta. already theta=tan(y/x) and r=sqrt(x^2+y^2).i writed this code but not the same graphic i have example for K=300 graphic;
clc, clear all
K=300;
x = linspace(0.02, 0.2, 20)
y = linspace( 0.02,0.2,20)
[x,y]=meshgrid(x,y);
r = sqrt(x.^2+y.^2)
theta=tan(y/x)
r = linspace(0.02, 0.2, 20); %20 values between 0.02 and 0.2
theta = linspace(0, pi/2, 20); %20 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))));
Sy = (K./(sqrt(2.*pi.*r)).*(cos(theta./2)).*(1+(sin(theta./2).*sin((3.*theta)./2))));
Sxy = (K./(sqrt(2.*pi.*r)).*cos(theta./2).*sin(theta./2).*cos((3.*theta)./2));
mesh(x,y,Sx)
Guillaume
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)

Sign in to comment.

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!