I am getting error while trying to get user input via
User_date=zenity_calendar()
error: datevec: none of the standard formats match the DATE string
error: called from
datevec at line 137 column 11
datestr at line 181 column 7
zenity_calendar at line 42 column 7
It is
win7 64bit system.
Octave version 4.2.1
zenity *| 0.5.7 | C:\Octave\OCTAVE~1.1\share\octave\packages\zenity-0.5.7
Any suggestion?
After debug.
pkg load zenity
d=zenity_calendar()
status = 0
output = 11/28/2017
datevec.m
line 142-146
[f, rY, ry, fy, fm, fd, fh, fmi, fs] = ...
__date_vfmt2sfmt__ (std_formats{l});
[found y(k) m(k) d(k) h(k) mi(k) s(k)] = ...
__date_str2vec__ (date{k}, p, f, rY, ry, fy, fm, fd, fh, fmi, fs);
results is
nd = 1
f = %m/%d/%Y
rY = 7
ry = 0
fy = 1
fm = 1
fd = 1
fh = 0
fmi = 0
fs = 0
found = 0
y = 0
m = 0
d = 0
h = 0
mi = 0
s = 0
I donot know how to fix it
Related
I have the following function:
% function file: lagrange.m
function Yint = lagrange( x, y, Xint )
n = length( x );
for i = 1 : n
L(i) = 1;
for j = 1 : n
if j ~= i
L(i) = L(i) * (Xint - x(j)) / (x(i) - x(j));
end
end
end
Yint = sum( y .* L );
end
Then I try to use it from this script:
% script file: roteiro_lagrange.m
clear all
x = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28];
y = [2.682942 3.818595 3.28224 2.486395 3.082151 5.441169 8.313973 9.978716 9.824237 8.911958 9.00002 10.92685 13.84033 15.98121 16.30058 15.42419 15.7721 16.49803$
xi = [16.8 18.2 2.8 15.1 19.2 5.6 13.1 19.8 8.2 10.9 20.0 10.7 8.4 19.8 13.0 5.8 19.2 15.0 3.0 18.3 16.7 0.2 16.9 18.1 2.6 15.3 19.1 5.4];
n = length(x)
ny = length(y)
YI = [];
for i = 1 : n
xp = xi(i);
for k = 2 : n
if x(k) > xp
xx = [x(k-1) x(k)];
yy = [y(k-1) y(k)];
yp = lagrange( xx, yy, xp );
YI = [YI yp];
break
endif
endfor
endfor
y_interp = YI'
plot( x, y, 'r', xi, YI, 'k*' )
but I get the following error when trying to run it:
lagrange
error: 'x' undefined near line 3 column 10
error: called from
lagrange at line 3 column 2
error: evaluating argument list element number 1
error: called from
lagrange at line 3 column 2
(see screenshots of the problem here: https://imgur.com/a/1b5WwDC )
You are calling the function directly, with no arguments (note, in matlab/octave, lagrange is exactly the same as doing lagrange() ).
You should be calling your script instead.
Trying to insert a data frame into a MySQL using the following code.
The data frame:
q <- data.frame( ... )
import_id time xpos ypos zpos gaps xvel yvel zvel trajectory runs
22651 2 188.7500 0.198364 0.484194 0.121778 0.000000 0.0000000 0.0000000000 0.0000000 0 1
22652 2 188.7583 0.200871 0.484247 0.119759 0.008333 0.3008520 0.0063602544 -0.2422897 1 6
22653 2 188.7667 0.203763 0.484246 0.117860 0.008334 0.3470122 -0.0001199904 -0.2278618 1 6
22654 2 188.7750 0.206539 0.484070 0.115836 0.008333 0.3331333 -0.0211208448 -0.2428897 1 6
22655 2 188.7833 0.209603 0.483557 0.113943 0.008333 0.3676947 -0.0615624625 -0.2271691 1 6
22656 2 188.7917 0.212570 0.482920 0.111810 0.008334 0.3560115 -0.0764338853 -0.2559395 1 6
RMySQL code:
dbWriteTable(conn = mysql_conn, name = "master", value = q,
append = TRUE, overwrite = FALSE, row.names = TRUE,
field.types = list(import_id="int(11)", time="float(15,8)",
xpos = "float(15,8)", ypos = "float(15,8)", zpos = "float(15,8)",
gpas = "float(15,8)", xvel = "float(15,8)", yvel = "float(15,8)",
zvel = "float(15,8)", trajectory = "int(11)", runs = "int(11)"))
Error:
Error in .local(conn, statement, ...) : could not run statement:
Unknown column 'row_names' in 'field list'
I Have a simple octave script
%! ## Example for linear inequality constraints
%! ## (see also the same example in 'demo nonlin_residmin')
%!
Ae = 1.5; ale = 0.1; omegae = 0.9 ; phie = 1.5;
noise = 0.1;
t = linspace(0,10,50);
n = noise*randn(size(t));
function y = f(t,p)
y = p(1)*exp(-p(2)*t).*cos(p(3)*t + p(4));
endfunction
y = f(t,[Ae,ale,omegae,phie])+ n;
plot(t,y,'+; data;')
% NOW try fit
A0 = 2; al0 = 0; omega0 = 1; phi0 = pi/2 ;
[fr,p] = leasqr(t,y,[A0,al0,omega0,phi0],'f',1e-10);
p
yFit = f(t,p);
plot(t,y,'+',t,yFit)
legend ('data','fit')
But I get an error in the leasqr package
I have these packages installed
Package Name | Version | Installation directory
--------------+---------+-----------------------
optim | 1.5.2 | /Users/Terence/octave/optim-1.5.2
struct | 1.0.15 | /Users/Terence/octave/struct-1.0.15
>> testNonlinearfit
error: '__plot_cmds__' undefined near line 296 column 3
error: called from
leasqr at line 296 column 3
testNonlinearfit at line 16 column 7
Any help much appreciated
I have a text file named file1.txt that is formatted like this:
001 , ID , 20000
002 , Name , Brandon
003 , Phone_Number , 616-234-1999
004 , SSNumber , 234-23-234
005 , Model , Toyota
007 , Engine ,V8
008 , GPS , OFF
and I have file2.txt formatted like this:
#==============================================
# 005 : Model
#------------------------------------------------------------------------------
[Model] = Honda
option = 0
length = 232
time = 1000
hp = 75.0
k1 = 0.3
k2 = 0.0
k1 = 0.3
k2 = 0.0
#------------------------------------------------------------------------------
[Model] = Toyota
option = 1
length = 223
time = 5000
speed = 50
CCNA = 1
#--------------------------------------------------------------------------
[Model] = Miata
option = 2
CCNA = 1
#==============================================
# 007 : Engine
#------------------------------------------------------------------------------
[Engine_Type] = V8 #1200HP
option = 0
p = 12.0
pp = 12.0
map = 0.4914
k1mat = 100
k2mat = 600
value =12.00
mep = 79.0
cylinders = 8
#------------------------------------------------------------------------------
[Engine_Type] = v6 #800HP
option = 1
active = 1
cylinders = 6
lim = 500
lim = 340
rpm = 330
start = 350
ul = 190.0
ll = 180.0
ul = 185.0
#==============================================
# 008 : GPS
#------------------------------------------------------------------------------
[GPS] = ON
monitor = 0
#------------------------------------------------------------------------------
[GPS] = OFF
monitor = 1
Enable = 1
#------------------------------------------------------------------------------
[GPS] = Only
monitor = 2
Enable = 1
#==============================================
# 014 :Option
#------------------------------------------------------------------------------
[Option] = Disable
monitor = 0
#------------------------------------------------------------------------------
[Option] = Enable
monitor = 1
#==============================================
# 015 : Weight
#------------------------------------------------------------------------------
[lbs] = &1
weight = &1
#==============================================
The expected output is supposed to look like this:
Since there is only option 005-008 in file1.txt the output would be:
Code:
#==============================================
# 005 : Model
#------------------------------------------------------------------------------
[Model] = Toyota
option = 1
length = 223
time = 5000
speed = 50
CCNA = 1
#==============================================
# 007 : Engine
#------------------------------------------------------------------------------
[Engine_Type] = V8 #1200HP
option = 0
p = 12.0
pp = 12.0
map = 0.4914
k1mat = 100
k2mat = 600
value =12.00
mep = 79.0
cylinders = 8
#==============================================
# 008 : GPS
#------------------------------------------------------------------------------
[GPS] = OFF
monitor = 1
Enable = 1
#-----------------------------------------------------------------
Now, using Awk and the values from the 2nd and 3rd columns in file1, I want to search for those strings in file2 and output everything in that section to a CSV file ie from where the string is found to where there is the #-------------
demarcation.
Could someone please help me with this and explain also? I am new to Awk
Thank you!
I wouldn't really use awk for this job as specified, but here's a little snippet to get started:
awk -F'[ ,]+' 'FNR == NR { section["[" $2 "]"] = $3; next }
/^\[/ && section[$1] == $3, /^#/' file1.txt file2.txt
1) The -F'[ ,]+' sets the field separator to one or more of spaces and/or commas (since file1.txt looks like it's not a proper CSV file).
2) FNR == NR (record number in file equals total record number) is only true when reading file1.txt. So for each line in file1.txt, we record [second_field] as the pattern to look for with the third field as value.
3) Then we look for lines that begin with a [ and where the value stored in section for the first field of that line matches the third field of that line (/^\[/ && section[$1] == $3), and print from that line until the next line that begins with a #.
The output for your example input is:
[Model] = Toyota
option = 1
length = 223
time = 5000
speed = 50
CCNA = 1
#--------------------------------------------------------------------------
[GPS] = OFF
monitor = 1
Enable = 1
#------------------------------------------------------------------------------
The matched lines in step 3 were [Model] = Toyota and [GPS] = OFF. The Engine line is missing because file2.txt had Engine_Type instead. Also, I didn't bother with the section headers; it would be easy to add another condition to print them all but it requires lookahead to print only the ones that are going to have matching content in them (because at the time you read the header you don't know if a match is found inside). For that, I would switch to another language (e.g., Ruby).
%%%CODE:
clc;
disp('Implementation of ELGAMAL Digital Signature');
clear all;
close all;
%%Hardcoded values (vpi stands for VariablePrecisionIntegers, and are used to store large values)
g = vpi(5) %alpha in example
k = vpi(9) %Random number 1<k<p-1 and gcd(k, p − 1) = 1.
p = vpi(23) %Prime Number
x = vpi(3) %Secret Key 1 < x < p − 1
m = vpi(7) %Message
y = vpi(2)
r = vpi(2)
s = vpi(2)
%%Key Generation
y = powermod(g,x,p) %y = g^x mod p
%%Signature Generation
r = powermod(g,k,p) %r = g^k mod p
multinver = mulinv(9,23) %Generates multiplicative inverse k^-1 mod p
s = mod(((multinver)*(m-x*r)),p-1) %s = (k^-1)*(m-x*r) mod p-1
%%Verification
zvg = vpi(2);
zvg = powermod (g,m,p) %zvg = g^m mod p
zvyr = vpi(2);
zvyr = mod(((y^r)*(r^s)),p) %zvyr = y^r * r^s mod p
Output:
Implementation of ELGAMAL Digital Signature
g = 5
k = 9
p = 23
x = 3
m = 7
y = 2
r = 2
s = 2
y = 10
r = 11
multinver = 18
s = 16
zvg = 17
zvyr = 5
zvg should be equal to zvyr, but it's coming out wrong.
You are computing multinver wrong
It should be
multinver = mulinv(k,p-1) %Generates multiplicative inverse k^-1 mod (p-1)
Notice that we are computing the inverse mod (p-1) not mod (p).