How do I use loops to model a function of displacement changing with respect to angle over time?

조회 수: 2 (최근 30일)
I have been trying to model the function of displacement (as you can see here: https://i.imgur.com/s6PXKSx.png). To do this I was trying to do a loop function on MATLAB, with a step size of 1/36th of a second from 0s to 1s.
Here is my code so far:
clear all
%recorded constants
h = 60;
b = 130;
r = 135;
w = 2*pi; % angular velocity
i=1;
for t =0:(1/36):1 % Starts from 2s with a step size of 2 until 60s
t2(i+1) = t; %Time function to progress with 1 step intervals
x(i+1)=b*((r*sin(wt)/((h-r)*cost(wt))
i=i+1;
end

채택된 답변

Aquatris
Aquatris 2018년 7월 24일
You have a few typos in your implementation and you do not need a for loop either. Here is the code;
h = 60;
b = 130;
r = 135;
w = 2*pi; % angular velocity
t =0:(1/36):1;
x = b*(r*sin(w*t))./(h-r*cos(w*t));
I recommend you insert the picture to your question next time using "image" icon, which makes it easier to answer the question.
  댓글 수: 3
Christian Aranas
Christian Aranas 2018년 7월 25일
Thank you so much! on another note, would matlab happen to have a time derivative function that could take the first and second derivatives of 'x' in my code?
Aquatris
Aquatris 2018년 7월 25일
There is the diff() function. Here is the link to its webpage , where you should look at the example for "Approximate Derivatives with diff".

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by