Writing a simple octave code to find factorial and check Sterling's approximation,
$ vi test.oct
function y=f(x)
y = 1;
for i=1:x
y = y*i;
endfor
endfunction
for i=1:170
x(i)=log(f(i));
y(i)=i*log(i)-i;
z(i)=100.*(x(i)-y(i))/(x(i));
endfor
plot(z)
$ source test.oct
I get the error
syntax error near unexpected token `y'
bash: test.oct: line 4: `y = y*i;'
How do I resolve the syntax error in defining variable y
Related
I ran this code to find the norm of some fundamnetal units of a biqaudratic number field, but I faced following problem
for (q=5, 200, for(p=q+1, 200, if (isprime(p)==1 && isprime(q)==1 ,k1=bnfinit(y^2-2*p,1); k2=bnfinit(y^2-q,1); k3=bnfinit(y^2-2*p*q,1); ep1=k1[8][5][1]; ep2=k2[8][5][1]; ep3=k3[8][5][1]; normep1=nfeltnorm(k1,ep1); normep2=nfeltnorm(k2,ep2); normep3=nfeltnorm(k3,ep3); li=[[q,p], [normep1, normep2, normep3]]; lis4=concat(lis4,[li]))))
and it works for small p and q. However, when I ran that for p and q greater than 150, it gives the following error:
First, I didn't use the flag=1 for bnf, but after adding that, still I get the same error.
Please, do not use indexing like ...[8][5][1] to get the fundamental units (FU). It seems that bnfinit omits FU matrix for some p and q. Instead, use the member function fu to receive FU. Please, find the example below:
> [q, p] = [23, 109];
> k = bnfinit(y^2 - 2*p*q, 1);
> k[8][5]
[;]
> k[8][5][1] \\ you will get the error here trying to index the empty matrix.
...
incorrect type in _[_] OCcompo1 [not a vector] (t_MAT).
> k.fu
[Mod(-355285121749346859670064114879166870*y - 25157598731408198132266996072608016699, y^2 - 5014)]
> norm(k.fu[1])
1
I have this code:
function var_leafdrop(var_inc, var_restpos)
If var_y >= var_restpos then
var_y = var_restpos
else
var_y = var_y + var_inc
end
return var_y
end
I get error:
error 18: '=' expected near 'var_y'
18 being the line:
If var_y >= var_restpos then
I've tried:
Changing the variable name
Changing its declaration
Removing the if then block
Moving the entire function to the beginning of the script file
This is using the built in script editor for Watchmaker.
I can't see any error!? I just don't get it. Is this some dumb idiosyncrasy with Watchmaker...?
As mentioned in the comments, Lua is case sensitive.
So use if instead of If.
I am trying to compile some fortran code using gfortran v.4.8.2.
When I compile, I get the following errors:
ant_driver.f90:185.72:
if (model%geometry%topg(ew,ns)-model%climate%eus(ew,ns)
1
Error: Syntax error in IF-expression at (1)
ant_driver.f90:187.119:
ry%thck(ew,ns) = -rhoo/rhoi * (model%geometry%topg(ew,ns)- model%climate%eus(ew,
1
Error: Expected a right parenthesis in expression at (1)
ant_driver.f90:188.27:
endif
1
Error: Expecting END DO statement at (1)
ant_driver.f90:248.82:
odel%geometry%usrf(ew,ns) = - (model%geometry%topg(ew,ns)-model%climate%eus(ew,
1
Error: Expected a right parenthesis in expression at (1)
ant_driver.f90:260.107:
model%geometry%usrf(ew,ns) - (model%geometry%topg(ew,ns)-model%climate%eus(ew,
1
Error: Expected a right parenthesis in expression at (1)
ant_driver.f90:174.30:
call glide_set_eus(model,eus)
1
Error: Rank mismatch in argument 'inarray' at (1) (scalar and rank-2)
The errors relate to the following lines of code:
185-188:
if (model%geometry%topg(ew,ns)-model%climate%eus(ew,ns) < 0 .and. model%geometry%thck(ew,ns) == 0 .and. &
mask(ew,ns) == 1) then
model%geometry%thck(ew,ns) = -rhoo/rhoi * (model%geometry%topg(ew,ns)-model%climate%eus(ew,ns))
endif
248:
model%geometry%usrf(ew,ns) = - (model%geometry%topg(ew,ns)-model%climate%eus(ew,ns)) * rhoo/rhoi &
+ (model%geometry%topg(ew,ns)-model%climate%eus(ew,ns))
260:
model%geometry%thck(ew,ns) = model%geometry%usrf(ew,ns) - (model%geometry%topg(ew,ns)-model%climate%eus(ew,ns))
174:
call glide_set_eus(model,eus)
Any help much appreciated. Thank you for your time.
Your errors are due to line truncation. For fixed-form Fortran a line length of 72 characters is specified and for free-form Fortran it should be 132 characters. You source should be interpreted as free-form due to the .f90 extension but you can force free-form in gfortran with -ffree-form. You can also alter the maximum line lengths in fixed- and free-form source with the options -ffixed-line-length-n and -ffree-line-length-n respectively, where n is the number of characters and values of 0 or none mean unlimited line length.
I have the following code:
term_to_packet(Term) ->
B = term_to_binary(Term),
A = byte_size(B),
<< 1:4/integer-unit:8, B:A/integer-unit:8 >>.
However, when I run:
term_to_packet("Hello").
I get an error:
exception error: bad argument in function term_to_packet line 20
where line 20 corresponds to the last line of the term_to_packet function.
I'm not quite sure what's throwing this error.
B is a binary, but in the binary construction on the last line you specify that it is an integer. This seems to work:
term_to_packet(Term) ->
B = term_to_binary(Term),
A = byte_size(B),
<< 1:4/integer-unit:8, B:A/binary-unit:8 >>.
I= 0.299*C1(:,:,1)+0.587*C1(:,:,2)+0.114*C1(:,:,3);
NumberOfGrayLevels=32;
I' =C ln (I+1);
new=uint8(mat2gray(I')*(NumberOfGrayLevels-1));
[m,n]= size(new);
rgb = zeros(m,n,3);
rgb(:,:,1) = new;
rgb(:,:,2) = rgb(:,:,1);
rgb(:,:,3) = rgb(:,:,1);
new = rgb/255;
imshow(new,[]);
no6=figure;
image(new);
this is the code for image generation. error is at I' = . it is showing that + is error.
I assume this is matlab. You're missing operators in the line with an error:
change the third line to:
I=(C*ln(I+1))';