Home > Software engineering >  animation to show generation of certain random line segments
animation to show generation of certain random line segments

Time:12-14

I am trying to understand these by myself

C,

I want to simulate some straight lines, in Matlab, as follows:

f(t,z)=a(z)t b(z) where a(z) and b(z) are uniformly distributed random variable in the interval [-1,1] and t is time between [-2,2]. More simply: f(t)= at b, and z is the random index of the constant (a,b) and let say [-1, 1] is the sample space for z and z is uniformly distributed.

Could anyone help me with the code? Is there any way to show the random generation of the straight line as an animation? Thank you very much for any help.

I am trying like this:

a= rand(-1,1);
b=rand(-1,1);
-2<t<2;
f=a*t b;
plot(t, f);
But I am getting error Unrecognized function or variable 't'.

CodePudding user response:

Your attempt is not valid MATLAB syntax,

  • -2<t<2 does not do anything, other than produce the error you're seeing because t does not exist

  • f = a*t b you can't define functions like this, you probably want to use an plot

    If you need an "animation", you could add a pause, e.g. pause(1) inside the loop

  • Related