How do I limit angle values in my equations to between 0-90°?

23 visualizaciones (últimos 30 días)
Jack Cross
Jack Cross el 27 de Sept. de 2020
Comentada: Jack Cross el 27 de Sept. de 2020
Hi there,
I'm including a simplified version of my code, along with the graph I'm getting from it. What I'm trying to do is to limit the angle m (or m_) to between 0 and 90 degrees only. Can anyone help?
clc
t=[0:0.01:1];
for j=1 : 101
syms m
m_ = solve(sind(m)==t(j), m);
y = zeros(numel(t), numel(m_)); % pre-allocation
y(j, :)=m_*30+5;
hold on
plot (t, y)
end

Respuestas (3)

Alan Stevens
Alan Stevens el 27 de Sept. de 2020
This does it
t=[0:0.01:1];
for j=1 : 101
m_ = rad2deg(asin(t(j)));
y = zeros(numel(t), numel(m_)); % pre-allocation
y(j, :)=m_*30+5;
hold on
plot (t, y)
end

Jack Cross
Jack Cross el 27 de Sept. de 2020
Hi Alan,
I see you solved the equation for m. That's great, the equation I need solving is a bit more complicated for t (see below). It was a bad example as it was easy to solve.
sqrt((2*dl*sind(theta(j)))/(Fy + (T1*dt/(m*dl)+T2*sind(theta(j))/m+W*dc/(m*dl))*cosd(theta(j))*sind(90-theta(j))))=t(j)
Does "rad2deg" help to keep the angles 0-90? Are you able to show a code with that and still keep the solve line in?
  2 comentarios
Alan Stevens
Alan Stevens el 27 de Sept. de 2020
rad2deg doesn't necessarily keep the angles between 0 and 90. but asin(x) where x is anything from 0 to 1, does (well, it keeps it between 0 and pi/2).
If you supply the other variable values, range of t etc. I'll have a look at your more complicated expression.
Jack Cross
Jack Cross el 27 de Sept. de 2020
That makes sence. I just posted the full code. Appreciate your help.

Iniciar sesión para comentar.


Jack Cross
Jack Cross el 27 de Sept. de 2020
Here's the whole code incase I'm being confusing:
clear all
clc
L=0.01;
g=9.81;
m=0.85;
T1=(L+0.5)*m*g;
T2=(L+0.5)*m*g;
W=m*g;
dc=0.15;
dt=0.3;
dl=0.3;
Fy=L*g;
t=[0:0.25:2.5];
for j=1 : 11
syms theta
theta_ = solve(sqrt((2*dl*sind(theta))/(Fy + (T1*dt/(m*dl)+T2*sind(theta)/m+W*dc/(m*dl))*cosd(theta)*sind(90-theta)))==t(j), theta);
y = zeros(numel(t),numel(theta_)); % pre-allocation
y(j, :)= dl*sind(theta_);
hold on
plot (t, y)
end
  5 comentarios
Alan Stevens
Alan Stevens el 27 de Sept. de 2020
After playing around a bit I managed to fill in the lower end, down to t = 0.01, as follows:
dl = 0.3;
t= 0.01:0.01:2.47;
theta_ = zeros(numel(t),1);
for j=1 : numel(t)
if t(j)<0.05
theta0 = 1;
elseif t(j)<0.1
theta0 = 8;
else
theta0 = 90;
end
theta_(j) = fzero(@zerofn,theta0,[],t(j));
end
y= dl*sind(theta_);
hold on
plot (t, y),grid
xlabel('t'),ylabel('y')
function F = zerofn(theta,t)
L=0.01;
g=9.81;
m=0.85;
T1=(L+0.5)*m*g;
T2=(L+0.5)*m*g;
W=m*g;
dc=0.15;
dt=0.3;
dl=0.3;
Fy=L*g;
F = sqrt((2*dl*sind(theta)) ...
/(Fy + (T1*dt/(m*dl)+T2*sind(theta)/m+W*dc/(m*dl)) ...
*cosd(theta)*sind(90-theta)))-t;
end
The resulting graph now looks like:
Jack Cross
Jack Cross el 27 de Sept. de 2020
I'm wondering if at t=0, all forces are in static equilibrium and that's why we're not getting any change in y until after t=0?

Iniciar sesión para comentar.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by