Code error with parameter
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
I'm trying to adapt my code below
rg = 0.01;
rl = 0.01;
s1 = [-1:0.000001:5];
x = ((s1-rg-rl)+sqrt((rg+rl-s1).^2+4.*s1.*rg))./(2.*s1);
採用された回答
Star Strider
2020 年 1 月 4 日
I am not certain what you want, however it most likely depends on how you define ‘t’.
Example —
rg = 0.01;
rl = 0.01;
s1 = [-1:0.000001:5];
x = ((s1-rg-rl)+sqrt((rg+rl-s1).^2+4.*s1.*rg))./(2.*s1);
t1 = 0:numel(s1)-1; % Define ‘t1’, Interval = 1 sec
t2 = (0:numel(s1)-1)*5; % Define ‘t2’, Interval = 5 sec
figure
plot(t1, x)
hold on
plot(t2, x)
hold off
grid
legend('\Delta t = 1 s', '\Delta t = 5 s', 'Location','E')
8 件のコメント
Ellen Brown
2020 年 1 月 4 日
I'm trying to get it to say e.g. s1 is drawn from an exponential distribution with mean 1 and s2 is drawn from an exponential distribution with mean 2, x will be calculated used the two states 's1' and 's2' , and which one it is calculated one from changes periodically every t time units.
Star Strider
2020 年 1 月 4 日
Are you intending to simulate a Poisson process?
Ellen Brown
2020 年 1 月 4 日
sorry I'm not explaining it clearly,
my s is simulated from a poisson:
U = rand(1,1000); % generate 1000 uniform (0,1) random variables
% use inverse transform method to generate 1000 exp rv with rate 1, mean
% shifted to -1
s = -log(1-U)-1;
but i want s to switch between two independent states s1 and s2, were s1 and s2 are simulated from:
s1 = -log(1-U)-1;
s2 = -log(1-U)-1;
I want to calculate x as s changes between two states, “s1” and “s2”, periodically every t time units, where x is:
x = ((s-rg-rl)+sqrt((rg+rl-s).^2+4.*s.*rg))./(2.*s);
Star Strider
2020 年 1 月 4 日
It appears that ‘s1’ and ‘s2’ are identical:
s1 = -log(1-U)-1;
s2 = -log(1-U)-1;
I’m still very much lost.
Ellen Brown
2020 年 1 月 4 日
編集済み: Ellen Brown
2020 年 1 月 4 日
ah typo, s2 is meant to be:
s2 = -log(1-U)+1;
I just want x to change which s it uses periodically, i.e. for first 5s it uses s1, then the next 5s it uses s2, then s1 again, e.t.c.
Star Strider
2020 年 1 月 4 日
I still have no clear idea of what you want.
The only thing I can think of is to use a loop:
rg = 0.01;
rl = 0.01;
U = rand(1,1000);
s1 = -log(1-U)-1;
s2 = -log(1-U)+1;
x = @(s) ((s-rg-rl)+sqrt((rg+rl-s).^2+4.*s.*rg))./(2.*s);
xs = zeros(size(U));
for k = 1: numel(U)
s_val = s1(k)*(rem(k,2)==0) + s2(k)*(rem(k,2)==1); % Even-Odd Values of ‘k’ Select ‘s’
xs(k) = x(s_val);
end
I am now completely out of ideas.
Ellen Brown
2020 年 1 月 4 日
That's exactly what I want! Thank you so much! I'm being a bit cheeky now but how would I get a vector of those s_val values? I'd like to plot xs against the s_val values
Star Strider
2020 年 1 月 4 日
As always, my pleasure!
Not cheeky at all! That’s a perfectly legitimate question.
To store the ‘s_val’ values (without re-writing the rest of the loop):
xs = zeros(size(U));
s_val_vct = xs;
for k = 1: numel(U)
s_val = s1(k)*(rem(k,2)==0) + s2(k)*(rem(k,2)==1); % Even-Odd Values of ‘k’ Select ‘s’
xs(k) = x(s_val);
s_val_vct(k) = s_val;
end
Then to plot them:
figure
plot(s_val_vct, xs, 'p')
grid
xlabel('s')
ylabel('x')
It’s best to plot them with markers, unlless you want to use the sort function to sort ‘xs’ and ‘s_val_vct’ and then plot with lines, because ‘s_val’ alternates between poisitive and negative values, and that would create a confusing and disordered plot. (I like plotting with pentagrams. Choose the marker you want.)
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Graphics Object Properties についてさらに検索
タグ
参考
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)
