function [x1, x2] = torus(a,b)
x1= ((.25*pi^2)*(a+b)*((b-a).^2));
x2= ((pi^2)*(b^2-a.^2));
end
> [volume, area]=torus(0.25:4,a+2)
Error using *
Inner matrix dimensions must agree.
Error in torus (line 2)
x1= ((.25*pi^2)*(a+b)*((b-a).^2));
How to go about correcting problem, I thought for the element wise for variables a and b I could just input them as the values for torus(a,b)

 Respuesta aceptada

James Tursa
James Tursa el 3 de Ag. de 2016
Editada: James Tursa el 3 de Ag. de 2016

2 votos

Use element-wise multiply operator .* instead of * which is matrix multiply:
x1= ((.25*pi^2)*(a+b).*((b-a).^2)); % <-- changed * to .*
x2= ((pi^2)*(b.^2-a.^2)); % <-- changed ^2 to .^2

1 comentario

Amber Scarbrough
Amber Scarbrough el 3 de Ag. de 2016
Thank you ran it again and gave me some answers. Thank you!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Get Started with MATLAB en Centro de ayuda y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by