Plotting for loop with two outputs
3 views (last 30 days)
I need to plot a function with a two variable output using any method. The graph should plot an x range of 2-1000000. I have used a for loop which should plot the prewritten function L, which outputs two different variables. Both are below.
%%This is the function that works. It is for the collatz conjecture.
function [N, mx] = prob3_6(x)
X=x;%to initialise an X value that is not the input
N=0; %to initialise an N value that starts with 0 iterations.
mx=x; %create a definition for max in terms of x.
while X~=1; %while x is not 1, ends when x=1 if ever
if mod(X,2); % if x is odd
X=1+3*X; % do calculation for odd input
X=X./2; %even numbers divided by 2
N=N+1 %for each loop, N will add 1 iteration from zero
if X>mx; % if an X value happens to be greater than the set max, which is the input,
mx=X %it will override that value with the new max.
%% This is the code that does not work for plotting the function
for X= 2:1000000;
How do I use a this loop to plot the function that I have made?