# I have a task where I have to calculate the area of a triangle from degrees 1 to 90, that is bound within a semi circle. I keep getting an error with the last line for some reason

5 views (last 30 days)
Beenish Shabir on 16 Oct 2020
Commented: Rena Berman on 7 May 2021 at 1:31
I have a task where I have to calculate the area of a triangle from degrees 1 to 90, that is bound within a semi circle. I keep getting an error with the last line for some reason.
alpha = (1:90)
b = a * cosd(alpha(1:90));
area = 0.5*a*sind(1:90)
triangle= area*b
##### 2 CommentsShowHide 1 older comment
Rena Berman on 7 May 2021 at 1:31

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:
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); ##### 2 CommentsShowHide 1 older comment
Image Analyst on 17 Oct 2020
You can Accept only one answer, so accept the best one. However you can also vote for that and the other(s) to award those persons additional reputation points also.

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
Beenish Shabir on 17 Oct 2020
omg thank u it works now!