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.
1 次查看(过去 30 天)
显示 更早的评论
8 个评论
Walter Roberson
2017-5-19
Steven Lord
2017-5-19
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.
Wasi von Deutschland
2017-5-19
编辑:Walter Roberson
2017-5-19
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.
Walter Roberson
2017-5-19
You start from t = 0, and then you subtract a positive value from that. Your time is running in reverse.
Walter Roberson
2017-5-20
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.
Walter Roberson
2017-5-20
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.
回答(1 个)
Walter Roberson
2017-5-21
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 个评论
Wasi von Deutschland
2017-5-22
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
Walter Roberson
2017-5-22
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.
Wasi von Deutschland
2017-5-22
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
Walter Roberson
2017-5-23
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.
Wasi von Deutschland
2017-5-23
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;
Walter Roberson
2017-5-23
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)
Wasi von Deutschland
2017-5-23
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
Walter Roberson
2017-5-23
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.
Wasi von Deutschland
2017-5-23
should it be like this?, what would you say about the rest of the code.
theta = theta + vel*delta_t;
Wasi von Deutschland
2017-5-24
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
Walter Roberson
2017-5-24
You are setting the angular velocity to that calculation instead of increasing your angular velocity by that calculation.
Wasi von Deutschland
2017-5-25
Sorry but I didn't understand you. did you mean velocity should have been increased by adding t
vel=acc*delta_t+t
Wasi von Deutschland
2017-5-25
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
Walter Roberson
2017-5-25
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.
Wasi von Deutschland
2017-5-26
The one other thing I've noticed is vel is not defined how can it be used?
Wasi von Deutschland
2017-5-26
Roberson could you please tell me when autograder used arguments 0,1 it makes mistake for other arguments it's perfect.
Walter Roberson
2017-5-26
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.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)