MATLAB: I am having trouble receiving user input in the following code. The code works alright if I enter the values. It just goes into a loop asking the same questions and the code doesn’t seem to input the entered values.

user input

function Untitled()
r=input(prompt6);
prompt='Enter initial timestep?';
t0=input(prompt);
prompt2='Enter final timestep?';
tfi=input(prompt2);
prompt3='Enter initial x?';
x0=input(prompt3);
prompt7='Enter initial y?';
y0=input(prompt7);
prompt8='Enter initial z?';
z0=input(prompt8);
xi=[x0 y0 z0];
[t,x]=ode45(@lorenz,[t0 tfi],xi);
plot(t,x(:,2));
function dx=lorenz(t,x)
prompt4='Enter sigma?';
sig=input(prompt4);
prompt5='Enter B?';
B=input(prompt5);
prompt6='Enter r?';
dx=[-sig sig 0;r -1 -x(1);0 x(1) -B]*x;

Best Answer

Remove your prompting from your lorenz function and put those into your Untitled code. Then pass them into the lorenz code using the technique described at http://www.mathworks.com/help/matlab/math/parameterizing-functions.html
Related Question