Quark
Quark

Reputation: 399

matlab error Matrix diminsion error

The following is my code. I'm trying to plot something in 3-D:

vp = 6000;
vs = 1.0e+03 .*[0.5000,    0.6094 ,   0.7188  ,  0.8281 ,   0.9375 ,   1.0469  ,  1.1562 ,   1.2656  ,  1.3750  ,  1.4844,    1.5938  ,  1.7031  ,  1.8125  ,  1.9219    ,2.0312  ,  2.1406,2.2500 ,   2.3594  ,  2.4688   , 2.5781    ,2.6875    ,2.7969   , 2.9062  ,  3.0156  ,  3.1250  ,  3.2344   , 3.3438   , 3.4531  ,  3.5625   , 3.6719    ,3.7812    ,3.8906];

% y= vp ./ vs;

y1= [12.0000,9.8462,    8.3478,    7.2453,    6.4000,    5.7313,    5.1892,       4.7407,    4.3636,    4.0421,    3.7647,    3.5229,    3.3103,    3.1220,    2.9538,    2.8029,2.6667    ,2.5430    ,2.4304    ,2.3273    ,2.2326    ,2.1453   , 2.0645    ,1.9896    ,1.9200    ,1.8551    ,1.7944    ,1.7376    ,1.6842    ,1.6340    ,1.5868    ,1.5422];

x = (0:0.2:2*pi); %# set a range for vale of x
[X, Y] = meshgrid(x, y);
p = sin(x);
theta= [0.0833,    0.1016,    0.1198,    0.1380 ,   0.1562 ,   0.1745   , 0.1927 ,   0.2109 ,   0.2292 ,   0.2474 ,   0.2656,    0.2839 ,   0.3021   , 0.3203,    0.3385  ,  0.3568,    0.3750,    0.3932,    0.4115,    0.4297 ,   0.4479 ,   0.4661  ,  0.4844  ,  0.5026 ,   0.5208 ,   0.5391  ,  0.5573  ,  0.5755    ,0.5938  ,  0.6120    ,0.6302   , 0.6484];
curl = ((theta .^ 2) - ((vs .* p) .^ 2) ) .^ 0.5

R_o = (1-2*(vs.^2)) ;
k_o = (1 -2*(vs.^2)./(R_o));
R_pv = (2*curl.^(-1)).*(k_o).*((sin(x)).^2);

mesh(x,R_pv,y1)

The problem is here:

curl = ((theta .^ 2) - ((vs .* p) .^ 2) ) .^ 0.5;

I get the following error:

??? Error using ==> times
Matrix dimensions must agree.

Error in ==> project1_Rpv at 11
curl= ((theta .^ 2) - ((vs .* p) .^ 2) ) .^ 0.5;

Attempt at problem:

I have a gut feeling that I'm messing up some matrices but not sure where. I made sure my matrices are 1x1 and are of the same length.

EDIT: Thanks to Oli Charlesworth, I've fix the length of vs. Now I'm getting the following error:

??? Error using ==> mesh at 80
Z must be a matrix, not a scalar or vector.

Error in ==> project1_Rpv at 18
mesh(x, R_pv, y1)   ## (x, y, z)

All of my matrices are 1x1 yet I'm still getting error.

Upvotes: 0

Views: 671

Answers (1)

Webfoot Witch Hat
Webfoot Witch Hat

Reputation: 81

Your first problem was that x didn't have the same length as vs, a problem which

x = linspace(0,2*pi, length(vs));

would have solved.

Your second problem is that if length(x) = n and length(R_pv) = m then size(y1) = [m, n] which it currently is not. If you type help mesh in matlab you should see why.

Upvotes: 1

Related Questions