3 views (last 30 days)

Image Analyst
on 16 Oct 2020

You need to be using .* instead of * to do an elemenet by element multiplication instead of a matrix multiplication. Try this:

radius = 2 * rand;

alpha = (1:90)

bases = radius * cosd(alpha) % A vector of 90 elements

heights = radius * sind(alpha) % A vector of 90 elements

triangle_areas = 0.5 * bases .* heights % A vector of 90 elements

% For optional fun, plot the area.

plot(alpha, triangle_areas, 'b.-', 'LineWidth', 2);

grid on;

xlabel('Angle', 'FontSize', 18);

ylabel('Area', 'FontSize', 18);

title('Triangle Area vs. Angle', 'FontSize', 18);

Image Analyst
on 17 Oct 2020

meghannmarie
on 16 Oct 2020

Edited: meghannmarie
on 16 Oct 2020

You need to use the dot operator if you are doing element wise multiplication (.*). You use just the asterick for matrix multiplication.

triangle= area.*b

Opportunities for recent engineering grads.

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

Start Hunting!
## 1 Comment

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/616498-how-do-i-multiply-two-elements#comment_1069568

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/616498-how-do-i-multiply-two-elements#comment_1069568

Sign in to comment.