Issue with finding precision and sine graph

8 ビュー (過去 30 日間)
Kaylee Chavez
Kaylee Chavez 2021 年 5 月 22 日
回答済み: Raag 2025 年 7 月 4 日
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')

回答 (1 件)

Raag
Raag 2025 年 7 月 4 日
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:

カテゴリ

Help Center および File ExchangeGraph and Network Algorithms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by