現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
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.
Wasi von Deutschland
2017 年 5 月 20 日
should be t=t+delta_t....? but my Auto grader says it's incorrect
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!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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 (한국어)