Error using dot(A,B) - size/dimension problem

Hello.
I get the error "Error using dot (line 15) A and B must be same size." (Which is dot(A,B) ) I have tried numbers of time now, and I still don't know what I am doing wrong here.
I have the normal vector. 'n' and a point 'x' in the plane and the output is 's' in my formula.
I have attempted to get same dimension with size, but it appears not to been working so well.
...
n = vector
x = point in a plane
size(x,dim)
size(n,dim)
s=x+2*(d-dot(x,n))*n;
...
Regards
Cillian

Réponses (2)

Daniel Shub
Daniel Shub le 4 Mai 2012

0 votes

The error seems pretty clear to me your n and x are different sizes.

8 commentaires

Cillian
Cillian le 4 Mai 2012
Yes, I know. But do you know how I can get them to the same size?
Daniel Shub
Daniel Shub le 4 Mai 2012
What does size(x) and size(n) return?
Cillian
Cillian le 4 Mai 2012
I changed my code a little:
a=size(x)
b=size(n)
s=x+2*(d-dot(a,b))*n;
a =
1 1
b =
3 1
ans =
-1.2815
-2.4222
-3.5629
Jan
Jan le 4 Mai 2012
The DOT product is defined for vectors of the same size only. If you want an operation between e.g. a [1 x 3] and a [1 x 4] vector, it cannot be a DOT product. Therefore you have either a bug in your code, or you want something else.
Daniel Shub
Daniel Shub le 4 Mai 2012
What do you think x and n represent?
Jan
Jan le 4 Mai 2012
Now your "a" is a scalar. Then using "*" instead of "dot" is recommended.
Cillian
Cillian le 4 Mai 2012
so, the multiplication sign "*" should be put on this way:
s=x+2*(d-(a*b))*n; ?
I tested it, and still got:
a =
1 1
b =
3 1
And some erros:
Error using *
Inner matrix dimensions must agree.
Error in spegel (line 8)
s=x+2*(d-(a*b))*n;
Jan
Jan le 4 Mai 2012
While the multiplication between "a" and "b" works now, I guess that "b" and "n" have different sizes and the matrix multiplication fails.
However, Cillian, it is time to stop the confused guessing. Please post the complete relevant part of the code and explain what you want to compute. It seems like there is a problem in the mathematical part already.

Connectez-vous pour commenter.

Cillian
Cillian le 4 Mai 2012
sorry that I haven't been so clear abut this. here is the code:
function s = mirror(x,A,B,C,D) % x is a point in the room.
normvect = [A;B;C;];
length = norm(normvect);
d = D/length; % d is a point in the plane
n = normvect/length; % n is a normal vector
s = x + 2*(d - dot(x,n))*n
end
I want to calculate the reflection image "s" of the point "x" in the plane.

Catégories

En savoir plus sur General Applications dans Centre d'aide et File Exchange

Question posée :

le 4 Mai 2012

Community Treasure Hunt

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

Start Hunting!

Translated by