Anyone could help me solving this problem or could you refer me to any video or link that can help. I have been trying to solve it for couple of hours. Your help will be appreciated.

8 Comments

If you post what you've done to try to solve this problem and ask a specific question you may receive some suggestions about how to move forward.
function T= pendulum( L, a0 )
delta_t = 1*10^-6;
g = 9.8;
t=0;
theta = a0;
while theta==0;
t = t- delta_t;
acc = - g/L*sin(theta);
vel=acc*t;
theta = theta + vel*t;
end
T = 4*t;
end
this is my code what I have done so far.
You start from t = 0, and then you subtract a positive value from that. Your time is running in reverse.
No, the angle decreases to 0. "each at a time separated from the one before it by delta_t = 1 x 10^(-6) s". So the angle decreases as the time increases.
should be t=t+delta_t....? but my Auto grader says it's incorrect
If your auto grader is saying that your existing version is correct, then go with your existing version. If your auto grader is saying that your existing version is incorrect, then perhaps you have more than one problem, with the reverse time being one of them.

Sign in to comment.

Answers (1)

You have
theta = a0;
while theta==0;
Your input, a0, is said to be a positive number less than pi. As it is a positive number, the test theta == 0 will fail, so the body of
while theta==0
is never going to execute.
I suggest you consider theta>0 instead of theta==0

22 Comments

it doesn't work so far, but I think it's because of t.
function T= pendulum( L, a0 )
delta_t = 1*10^-6;
g = 9.8;
t=0;
theta = a0;
while theta>0;
delta_t=0:delta_t;
acc = - g/L*sin(theta);
vel=acc*t;
theta = theta + vel*t;
end
T = 4*t;
end
Why are you changing delta_t ? Why are you not changing t?
Note:
delta_t = 1*10^-6;
delta_t=0:delta_t;
together would be like
delta_t = 0:1*10^-6
which in turn means
delta_t = 0 : 1 : 1*10^-6
and with 1*10^-6 being less than 0+1, there is only room for a single value in the range, namely 0 itself. So your
delta_t=0:delta_t;
is the same as
delta_t = 0;
which is clearly wrong.
Actually it's not fine. Could you please tell me where I'm still having problem?
function T= pendulum( L, a0 )
delta_t=1*10^-6;
g = 9.8;
theta = a0;
while theta>0;
t =0:1 : delta_t;
vel=acc*delta_t;
theta = theta + vel*delta_t;
acc = - g*sin(theta)/L;
end
T = 4*t;
end
I went through and explained why 0:1:delta_t is going to give you just 0.
You should not be assigning t a range inside the loop. You should be adding delta_t to t, like we discussed before.
Meanwhile... you have not initialized acc.
I'm really sorry to say but I still have some confusion. I'm very beginner
  • t should not be inside the loop that what you meant.
  • t for first periodic movement is equals to 0 and then t=t+delta_t
  • theta should be inside loop while theta>0 or while == 0;
Just making this pair of corrections to what you wrote earlier, and not attempting to verify that any of the rest of the code is correct:
function T= pendulum( L, a0 )
delta_t = 1*10^-6;
g = 9.8;
t=0;
theta = a0;
while theta>0;
t = t + delta_t;
acc = - g/L*sin(theta);
vel = acc*t;
theta = theta + vel*t;
end
T = 4*t;
end
You should consider, though, that your change in angle does not depend upon your current velocity multiplied by the entire time that you have been swinging (t): your change in angle depends upon your current velocity multiplied by the change in time over which you are swinging (delta_t)
Could you please verify the whole code? I don't think I can figure out spending couple of hours more. It's been 3 days so far.
function T= pendulum( L, a0 )
delta_t = 1*10^-6;
g = 9.8;
t=0;
theta = a0;
while theta>0;
t = t + delta_t;
acc = - g/L*sin(theta);
vel = acc*delta_t; %fix delta_t for velocity
theta = theta + vel*t; % current velocity multiplied by change in time
end
T = 4*t;
end
Your line
theta = theta + vel*t; % current velocity multiplied by change in time
is not multiplying by the change in time, it is multiplying by the entire time the system has been in operation.
should it be like this?, what would you say about the rest of the code.
theta = theta + vel*delta_t;
loop doesn't end. It's busy. I am using this code
function T= pendulum( L, a0 )
delta_t = 1*10^-6;
g = 9.8;
t=0;
theta = a0;
while theta>0;
t = t + delta_t;
acc = - g/L*sin(theta);
vel = acc*delta_t;
theta = theta + vel*delta_t;
end
T = 4*t;
end
You are setting the angular velocity to that calculation instead of increasing your angular velocity by that calculation.
Sorry but I didn't understand you. did you mean velocity should have been increased by adding t
vel=acc*delta_t+t
I don't know what should I say.? I really appreciate your effort but my answer is still incorrect.
function T= pendulum( L, a0 )
delta_t = 1*10^-6;
g = 9.8;
t=0;
theta = a0;
while theta<=0
t = t + delta_t;
acc = - g/L*sin(theta);
vel = vel + acc*delta_t;
theta = theta+ vel*delta_t;
end
T = 4*t;
end
The code is to be called with a positive a0, so your initial theta will be positive, so you would immediately fail the "while theta<=0" test.
The one other thing I've noticed is vel is not defined how can it be used?
Roberson could you please tell me when autograder used arguments 0,1 it makes mistake for other arguments it's perfect.
Your code appears to return 4e-6 when called with argument 0, 1. That is a completely reasonable answer for the method of calculation that you are directed to use.
It is not a fair question: although the theoretic answer is that a pendulum of length 0 has infinite velocity and 0 period, it is also the case that a pendulum of length 0 is a point source and so cannot be said to move through any angle. Your given task is not to calculate the theoretical answer but rather to simulate the movement, and simulation requires a minimum of one time-step.
Their description of the calculation specifically talks about counting until the pendulum has "passed through" its lowest point, and if you can say with any assurance that the pendulum is "at" 1 radian then it takes a time-step to evolve to be "at" any other angle. If a pendulum of length 0 is "at" 1 radian at time 0, then no seconds later it cannot have changed to be "at" a different angle. If you want to talk about a 0 length pendulum then you would have to say that the angle is undefined, which would correspond to pendulum(1, nan) and your code returns 0 for that.

Sign in to comment.

Asked:

on 19 May 2017

Commented:

on 26 May 2017

Community Treasure Hunt

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

Start Hunting!