이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
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 (한국어)