Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
函数的随机迭代&Matlab格式_Matlab - Fatal编程技术网

函数的随机迭代&Matlab格式

函数的随机迭代&Matlab格式,matlab,Matlab,有谁能用Matlab代码帮我做下面的迭代方案吗,我们从给定的$x\in\mathbb R$开始,然后用概率$p_1,p_2=1-p_2$,我们选择$g_1$和$g_2$,这样做10$次,然后我开始从$11^{th}$迭代中用概率$q_1,q_2=1-q_1$选择它们,其中$p_1\ne p_2\ne q_1\ne q_2$ 我确实喜欢这样,但似乎无法实现我描述的场景。谢谢你的帮助 x0=something; cumweight= [p_1; 1-p_1]; g1=x^2+1; g2=3*x+x^

有谁能用Matlab代码帮我做下面的迭代方案吗,我们从给定的$x\in\mathbb R$开始,然后用概率$p_1,p_2=1-p_2$,我们选择$g_1$和$g_2$,这样做10$次,然后我开始从$11^{th}$迭代中用概率$q_1,q_2=1-q_1$选择它们,其中$p_1\ne p_2\ne q_1\ne q_2$

我确实喜欢这样,但似乎无法实现我描述的场景。谢谢你的帮助

x0=something;
cumweight= [p_1; 1-p_1];
g1=x^2+1;
g2=3*x+x^2+1;
x = zeros(n,1);
y = zeros(n,1);

    n=20;
for i=1:10
    r = rand;
    choice = find(cumweight >r, 1 );
    switch (choice)
        case 1
            g1(i+1)=g1(x0);
        case 2 
            g2(i+1)=g2(x0);

    end
end

这是一个脚本,它以概率独立地选择g和θ
(i) [p,1-p]我认为你的问题格式不好,很难理解。请说清楚一点。要将文本标记为代码,请使用成对的`,而不是$@Eliahu。显然,OP正在尝试在此处编写LaTeX;这是不支持在这个网站上我不觉得乳胶特别容易在这样的一个段落分析。请用不需要乳胶的方式提出你的问题。另外,如果我试图运行你的代码,我会得到一个错误“
something
undefined”。请确保我们可以实际运行您的代码,请参阅。“此网站应支持LaTeX”,但显然它不支持。当你发布一个问题时,你可以看到你的LaTeX没有被格式化,为什么还要选择这样发布呢?现在,您已将您的问题发布为图像,该图像不可搜索且不可供所有人访问(例如,屏幕阅读器将无法阅读您的问题)。相反,用普通的语言和代码写你的问题。如果你的问题需要数学知识,显然这个网站不是合适的。(提示:您的问题不需要任何数学符号就可以理解。)代码现在只需在g1和g2之间进行选择,您可以在此处输入非线性运算,并将其保存在变量say out(i)=某个函数中。然后,您可以绘制出变量。如果您有2个以上的g可供选择,一种方法是,您可以从多项式分布(查看wiki和matlab帮助)中绘制随机数,而不是从unifrom分布中绘制随机数。然后可以使用“开关”而不是“if-else”。提示:test=find(mnrnd(1,[p1 p2 p3 p4 p5 p6])将在测试中为您提供一个介于1-6之间的值,其中p1…p6是6个案例总和为1的概率。
clc
clear all
close all
%x0=something;
p_1 = 0.2;
q_1 = 0.3;
g1=1;
g2=2;
theta1 = 1;
theta2 = 2;
n = 20;
x = zeros(n,1);
y = zeros(n,1);    
for i=1:20
    r1 = rand; % random number of choice of g1/g2
    r2 = rand; % random number of choice of theta1/theta2

    if(i <= 10)
         test = p_1;
    elseif(i <= 20) 
         test = q_1;
    end

    choiceG = test <= r1;
    choiceTheta = test <= r2;

    % chose theta
    if(choiceTheta)
        theta = theta1;
    else
        theta = theta2;
    end

    % chose G
    if(choiceG)
        % the text below is chosen with probability p_1 for i <=10 and
        % with probability q_1 for 11 <= i <= 20
        g = g1;
    else
        % the text below is chosen with probability (1 - p_1) for i <=10 and
        % with probability (1-q_1) for 11 <= i <= 20
        g = g2;
    end

    disp([' chose g' num2str(g) ' and theta' num2str(theta)]) % only for ilustration purpose
    % you can set the required computation for x_{n+1} here
end