Clear Filters
Clear Filters

Greetings, and warn wishes for the new year. I need help in plotting a graph of a equation defined by 3 variables. two of them are lengths and the third one is the angle. So i want to have the values plotted for all different angles.

2 views (last 30 days)
Here's code i wrote. it runs without any error but i dont see any line plot in the figure. As the equation is a sine function i want to get a plot of sine wave.
With the below codes i get the value of T in each degree from 0 to 360 at unit interval. And i also need to get the average of these values.
Can you please help me this?
I hope i was able to present my question in a understandable way.
i am happy to further clarify.
sdad
hnb
clc; clear all; close all;
l = 0.1; % length of connecting rod
r= 0.05; % radius of crank arm
P = 500000; %pressure of the system in pascals
d= 0.05; % diameter of cylinder
A = (pi*d^2)/4; % area of the cylinder
F=P*A;
for B = 0:10:360 %angle
f=F/(l*(sqrt(1-(r^2/l^2)*(sin(B))^2)));
T = (f*r/l)*(sin(B))*(r*cos(B)+l*sqrt(1-(r^2/l^2)*(sin(B))^2)) % equation
plot (B,T ); hold on
end
xlabel("Angle (degrees))")
ylabel("Torque (Nm)")
grid on

Accepted Answer

madhan ravi
madhan ravi on 2 Jan 2019
Edited: madhan ravi on 2 Jan 2019
You don't need a loop at all :
clc; clear all; close all;
l = 0.1; % length of connecting rod
r= 0.05; % radius of crank arm
P = 500000; %pressure of the system in pascals
d= 0.05; % diameter of cylinder
A = (pi*d^2)/4; % area of the cylinder
F=P*A;
B = 0:10:360 %angle
f=F./(l.*(sqrt(1-(r.^2./l.^2).*(sin(B)).^2)));
T = (f.*r./l).*(sin(B)).*(r*cos(B)+l.*sqrt(1-(r.^2./l.^2).*(sin(B)).^2)) % equation
xx=linspace(B(1),B(end),1000);
yy=interp1(B,T,xx,'pchip'); % if you need a smooth curve
plot(B,T,'o',xx,yy,'r');
xlabel("Angle (degrees)")
ylabel("Torque (Nm)")
grid on
Screen Shot 2019-01-02 at 10.16.59 AM.png

More Answers (0)

Categories

Find more on Programming 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!