Issue with finding precision and sine graph

6 views (last 30 days)
Kaylee Chavez
Kaylee Chavez on 22 May 2021
Answered: Raag on 4 Jul 2025
Hi there.
I am working on a code for my statics class and I am running into a couple of problems with the code. First, we have to demonstrate a sine graph, such as in the reference photo. However, when I compile the graph, it does not graph correctly. Also, I am having trouble actually creating the precision graph. I am not sure how to write the loop for the weight vs the angle. Here is my reference photo:
I have attached the code below.
%%Oblique Balance Script
figure('Name','Team A Graphs');
clf;
%%Weight Ratio
subplot(2,1,1)
t=[0:0.01:180]
r = sind(30 + t) ./ sind(30 - t);
plot(t, r);
area(t,r,'FaceColor',[.8,.9,1.0]);
%Weight Graph
title('Weight ratio')
xlabel('Angle change')
ylabel('Ratio')
%%Precision
%%Precision Equation
subplot(2,1,2)
P =
Invalid expression. Check for missing or extra characters.
plot(, P);
area(,P,'FaceColor',[.8,.9,1.0]);
%Weight Graph
title('Precision Graph')
xlabel('Percent')
ylabel('Weight Ratio')

Answers (1)

Raag
Raag on 4 Jul 2025
Hi Kaylee,
As per my understanding, you are trying to plot two graphs: one showing the weight ratio based on a sine function, and another showing the precision of that ratio as the angle changes.
Your formula for the weight ratio is correct. To make the graph more informative and match the reference, consider adding horizontal reference lines at key ratio values.
You might also want to set appropriate y-axis limits and enable grid lines for clarity:
yline(2, 'r--');
yline(0.5, 'r--');
ylim([0 5]);
grid on;
For the precision graph, you’ll want to compute how much the weight ratio changes with small angle variations. A loop can help you calculate this using neighbouring values. Here's a how to structure it:
P = zeros(size(W)); % W is your weight ratio array
for i = 2:length(W)-1
% Compute relative change with neighbors
P(i) = max(abs(W(i-1) - W(i)), abs(W(i+1) - W(i))) / W(i) * 100;
end
Then, you can plot P against t and optionally add a horizontal line at 6% to indicate your precision threshold.
These changes should help you replicate the reference plots more accurately.
For more details, refer:

Categories

Find more on Graph and Network Algorithms in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!