0

The code

 function hennonMap(a, b, xn, yn, upper)
 Xval = zeros(upper, 1);
 Yval = zeros(upper, 1);
 for i=1:upper
Xval(i) = xn;
Yval(i) = yn;
x  = yn + 1 - a*xn^2;
y  = b * xn;
xn = x;
yn = y;
end
end

Is giving me zeros, can anyone see why?

  • What are you hoping will happen? – copper.hat Dec 07 '18 at 07:25
  • What values do you give to a, b, xn, yn and upper? –  Dec 07 '18 at 07:26
  • @copper.hat generate some values corresponding to iterations of the map? – user21312 Dec 07 '18 at 07:31
  • @MathFun123 I started with the standard $a=1.4$ $b=0.3$ and took the origin as inital value and $100$ iterations. – user21312 Dec 07 '18 at 07:32
  • There are no outputs declared. What are you expecting the function to do? Print out some values at each iteration. Try something. – copper.hat Dec 07 '18 at 07:34
  • @copper.hat I tried calling "Xval" after running it. – user21312 Dec 07 '18 at 07:37
  • You need to read the manual or start with simple examples. This is not a Matlab sponsored teaching site. – copper.hat Dec 07 '18 at 07:38
  • Xval is inside the function, so MATLAB doesn't remember it. If you want to gain information from a function, you have to return the information. –  Dec 07 '18 at 07:39
  • @MathFun123 it was all zeros which imo means that I must been saved, right? – user21312 Dec 07 '18 at 07:40
  • @copper.hat cant you just ignore the question? – user21312 Dec 07 '18 at 07:41
  • You are not paying any attention to the comments or my questions. How do you expect the function to do anything if you have no outputs? – copper.hat Dec 07 '18 at 07:45
  • @copper.hat I can explain. I was under the impression that the values "Xval" would be "saved" in "Xval" when runnig the function. Even if we are not asking it to print or declaring output. To me that is seperate things, but not to those who designed matlab apparently. – user21312 Dec 07 '18 at 07:49
  • @copper.hat this is particularly illogical since it did return zeros, but that might have stemmed from some missclick from me before. – user21312 Dec 07 '18 at 07:51

1 Answers1

0

Try this:

function [Xval,Yval] = hennonMap(a, b, xn, yn, upper)
Xval = zeros(upper, 1);
Yval = zeros(upper, 1);
for i=1:upper
Xval(i) = xn;
Yval(i) = yn;
x  = yn + 1 - a*xn^2;
y  = b * xn;
xn = x;
yn = y;
end
end
  • thanks, I just skipped the function part instead then I got it to work. But now I understand the problem with the other one. Ill try this before taking this answer. – user21312 Dec 07 '18 at 07:44
  • I do find it kind of odd that "Xval" returns zeros even if it didnt get "saved", if it didnt get saved it should just say "error" when calling it. – user21312 Dec 07 '18 at 07:47
  • Yes I also don't know why, but does it work now? –  Dec 07 '18 at 08:14
  • yes it works fine now – user21312 Dec 07 '18 at 19:34