I need to write a code for raising x to the power of y in Marie.js. That's what I have for now, however it spits out an error SyntaxError:L41 - Unknown label Loop.
Input
Subt One
Store Count
Input
Store x
Store y
Jns Exp
Load Wyn
Output
End, Halt
Exp, Hex 0
Loop2, Load Count
Skipcond 800
JumpI Exp
JnS Multi
Load Wyn
Store x
Load Count
Subt One
Store Count
Jump Loop2
Multi, Hex 0
Load Zero
Store Wyn
Loop, Load x
Skipcond 800
JumpI Multi
Load Wyn
Add y
Store Wyn
Load x
Subt One
Store x
Jump Loop
x, Dec 2
y, Dec 3
Zero, Dec 0
One, Dec 1
Wyn, Dec 0
Count, Dec 0
I understand the necessity for 2 loops, which execute y-1 times, however Im completely clueless what I'm doing wrong.
You have to define a label before you can Jump to it; you have not defined the label Loop. You have defined a label named Loop2.
Related
ORG 100 /Start Here
INPUT
Store X /Store 1st input value in X
INPUT
Store Y / Store 2nd input value in Y
choice, INPUT
Store C /Store choice in C
if, Load C
Subt A
Skipcond 400
Jump elseif1
JnS ADDITION /Call subroutine
Jump end
elseif1, Load C
Subt S
Skipcond 400
Jump elseif2
JnS SUBTRACT /Call subroutine
Jump end
elseif2, Load C
Subt M
Skipcond 400
Jump elseif3
JnS MULTIPLY /Call subroutine
Jump end
elseif3, Load C
Subt D
Skipcond 400
Jump elseif4
JnS DIVISION /Call subroutine
Jump end
elseif4, Load C
Subt Q
Skipcond 400
Jump choice /re-enter choice
Halt /stop the program
end, Output /Display the value
Halt /Stop
X, DEC 0
Y, DEC 0
C, DEC 0
/add two numbers
ADDITION Load X
Add Y
JumpI ADDITION / Indirect jump to return.
/subtract two numbers
SUBTRACT Load X
Subt Y
JumpI SUBTRACT / Indirect jump to return.
/multiply two numbers using continuous add loop
MULTIPLY loop, Load num
Add X
Store num
Load Y
Subt one
Store Y
Skipcond 400
Jump loop
Load num
JumpI MULTIPLY / Indirect jump to return.
/divide two numbers and return the quotient
DIVIDE If, Load X
Subt Y
Skipcond 800
Jump EndIf
Store X
Load quo
Add one
Store quo
Jump If
EndIf, Load quo
JumpI DIVIDE / Indirect jump to return.
/constants values
one, DEC 1
num, DEC 0
rem, DEC 0
quo, DEC 0
A, DEC 97 /a
M, DEC 109 /m
S, DEC 115 /s
D, DEC 100 /d
Q, DEC 113 /q
This is a calculator that is supposed to add, subtract, multiply, and divide. Once the user is done with an operand it is supposed to directly go to the next one as well, but it is giving me errors and I can't seem to fix them. Everything looks fine to me but it keeps saying "Operand undefined." I'm sure this is an obvious error to others but I can't seem to fix it. Was hoping someone can help me with this! Thanks!
I am very new to using Marie simulator, and if anyone could help, it would be great.
the following program:
ORG 200
If, Load X
Subt Y
Skipcond 400
Jump Else
Then, Load Y
Store X
Jump Endif
Else, Load Y
add X
Store Y
Endif, Output
Halt
Two, Dec 2
X, Dec 10
Y, Dec 10
END
From this code, what does this particular part mean? And how do I input a new value to Y? Also, what does first load instruction mean?
Two, Dec 2
X, Dec 10
Y, Dec 10
I am trying to figure this MarieSim out, I would really appreciate it if anyone could help out. thank u.
I just have a problem with graphing different plots on the same graph within a ‘for’ loop. I hope someone can be point me in the right direction.
I have a 2-D array, with discrete chunks of data in and amongst zeros. My data is the following:
A=
0 0
0 0
0 0
3 9
4 10
5 11
6 12
0 0
0 0
0 0
0 0
7 9.7
8 9.8
9 9.9
0 0
0 0
A chunk of data is defined as contiguous set of data, without interruptions of a [0 0] row. So in this example, the 1st chunk of data would be
3 9
4 10
5 11
6 12
And 2nd chunk is
7 9.7
8 9.8
9 9.9
The first column is x and second column is y. I would like to plot y as a function of x (x is horizontal axis, y is vertical axis) I want to plot these data sets on the same graph as a scatter graph, and put a line of best fit through the points, whenever I come across a chunk of data. In this case, I will have 2 sets of points and 2 lines of best fit (because I have 2 chunks of data). I would also like to calculate the R-squared value
The code that I have so far is shown below:
fh1 = figure;
hold all;
ah1 = gca;
% plot graphs:
for d = 1:max_number_zeros+num_rows
if sequence_holder(d,1)==0
continue;
end
c = d;
while sequence_holder(c,1)~=0
plot(ah1,sequence_holder(c,1),sequence_holder(c,num_cols),'*');
%lsline;
c =c+1;
continue;
end
end
Sequence holder is the array with the data in it. I can only plot the first set of data, with no line of best fit. I tried lsline, but that didn't work.
Can anyone tell me how to
-plot both sets of graphs
-how to draw a line of best fit a get the regression coefficient?
The first part could be done in a number of ways. I would test the second column for zeroness
zerodata = A(:,2) == 0;
which will give you a logical array of ones and zeros like [1 1 1 0 1 0 0 ...]. Then you can use this to split up your input. You could look at the diff of that array and test it for positive or negative sign. Your data starts on 0 so you won't get a transition for that one, so you'd need to think of some way to deal with that or the opposite case, unless you know for certain that it will always be one way or the other. You could just test the first element, or you could insert a known value at the start of your input array.
You will then have to store your chunks. As they may be of variable length and variable number you wouldn't put them into a big matrix, but you still want to be able to use a loop. I would use either a cell array, where each cell in a row contains the x or y data for a chunk, or a struct array where say structarray(1).x and structarray)1).y hold your data values.
Then you can iterate through your struct array and call plot on each chunk separately.
As for fitting you can use the fit command. It's complex and has lots of options so you should check out the help first (type doc fit inside the console to get the inline help, which is the same as the website help in content). The short version is that you can do a simple linear fit like this
[fitobject, gof] = fit(x, y, 'poly1');
where 'poly1' specifies you want a first order polynomial (i.e. straight line) and the output arguments give you a fit object, which you can do various things with like plot or interpolate, and the second gives you a struct containing among other things the r^2 and adjusted r^2. The fitobject also contains your fit coefficients.
multiplication of two numbers 6 and 3 by, repeatedly addition of 3 six times,using a loop that will add 3 six times and store the result into accumulator.
INPUT
STORE x
INPUT
STORE y
loop, LOAD x
ADD multiply
STORE multiply
LOAD y
SUBT one
STORE y
SKIPCOND 400
JUMP loop
LOAD multiply
OUTPUT
HALT
x, Dec 0
y, Dec 0
one, Dec 1
multiply, Dec 0
I have a series of times and returns in various matrices lets call them a b c. They are all x by 2 with column 1 being times in seconds and column 2 returns. While all the returns are over a set series of time intervals like 15s 30s 45s etc the problem is not all the matrices have all the time buckets so while a might be a 30 by 2 , b might only be a 28 by 2. Because it is missing say time 45 seconds and a return. I want to go through each matrix and where I am missing a time bucket I want to insert the bucket with a zero return - I am happy to create a control 30 by 1 matrix with all the times that need to be cross referenced
You can use ismember to locate these missing positions, so if a is the control vector and b is the missing data vector ind=find(ismember(a,b)==0); will give you the indices of a that are missing in b.
For example:
a=1:10;
b=[1:2 4:5 7:10];
ind=find(ismember(a,b)==0);
ind =
3 6
In order to to add zeros in the right places for b just
for n=1:numel(ind)
b=[b(1:ind(n)-1) , 0 , b(ind(n):end)];
end
b =
1 2 0 4 5 0 7 8 9 10