Problem with a lab
Show older comments
I have a lab problem. It says to write a program to iteratively generate points in two-dimensional space using the following rules:
(x_{n+1},y_{n+1}) =
/ (0.5,0.27*y_n), with 2% probability;
|
| (-0.139*x_n + 0.263*y_n + 0.57, 0.246*x_n + 0.224*y_n - 0.036), with 15% probability;
<
| (0.17*x_n - 0.215*y_n + 0.408, 0.222*x_n + 0.176*y_n + 0.0893), with 13% probability;
|
\ (0.781*x_n + 0.034*y_n + 0.1075, -0.032*x_n + 0.739*y_n + 0.27), with 70% probability.
[Click for pdf version of this problem, where you may find the equation easier to read.]
Start from an initial point (x_1,y_1)=(0.5,0.0). Carry out the iteration at least 30,000 times and plot all the data you obtain (as points) in an x-y plot.
I have written:
for iter = 1: 30000
r = rand();
x = 0.5;
y = 0;
if r < 0.02
y = y * 0.27*r;
elseif r < 0.02 + 0.15
x = x -0.139 * r + 0.246 * r;
y = y + 0.263 * r + 0.224 * r - 0.036;
elseif r < 0.02 + 0.15 + 0.13
x = x + 0.17 * r - 0.032 * r;
y = y + 0.034 * r + 0.739 * r + 0.27;
elseif r < 0.02 + 0.15 + 0.13 + 0.70
x = x + 0.781 * r - 0.032 * r;
y = y + 0.034 * r + 0.1075 + 0.739 * r + 0.27;
end
end
...doesn't seem to work; only outputs one x, y, and r value without repeating 30000 times. What's the issue?
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!