I am running a CLISP in mac os X terminal. A simple eval like (% 3 5) outputs
EVAL: UNDEFINED FUNCTION %
It evaluates correctly in the ielm mode in emacs. Thanks in advance for the help
The name of the function is rem: (rem 5 3)
Related
In my old 2007 Matlab code, I was doing modulo operation on symbolic varaibles as follows:
syms x
if (mod(5*x, x) == 0)
in = 1
end
Today I ran the same program in R2013a and I am getting
mod(5*x, x)= x*(5 mod x)
Due to this result, the if condition is not passed. As a result, my program is aborting.
I am not able to understand the reasons for this. I appreciate your comments.
Thanks in advance.
Basically I'm running Octave 4.2.1 in Emacs 25.2.1 all within iTerm2 on macOS Sierra and every time I run a function (any function), a list of what look like command names is printed before the answer. I have tried to look up to see if this has been answered, but I'm having trouble describing the output list in a search. Here is the function command:
octave> f(3)
where f is declared as:
octave> function y = f(x)
>y = x + 10;
>endfunction
and the output is:
yes_or_no
ylabel
ylim
yulewalker
x
xlabel
xlim
xor
end
end_try_catch
end_unwind_protect
endfor
endfunction
endgrent
endif
endparfor
endpwent
endswitch
endwhile
endfunction
endfunction
ans = 13
I have tried placing semicolons at the end of every line (because I was unsure if this is function output that could be silenced with a semicolon), but that didn't pan out.
Edit: I have also tried turning off diary because I'm not sure that diary is. Needless to say, did not work out.
Let me know what I can do to stop this output. And if this is a duplicate due to me not having the vocabulary to search for my solution, obviously just mark it and I'll follow the link.
Thanks!
I want the xlabel of my Matlab figure to read v / Uinf, where the v has an overbar, and the inf is a symbol in subscript.
The line:
xlabel('$\bar{v}$','interpreter','latex')
creates the v overbar, and:
xlabel('U_\infty')
creates the U subscript infinity, but when I try to put them together, Matlab says 'String must have valid interpreter syntax'. It seems setting the interpreter to latex means the U_\infty command doesn't work any more.
Is there a way of writing U_infty that is compatible with latex or another way of writing the two together?
Thanks in advance,
Holly
In LaTeX, U_\infty works only in math mode, so you have to write $U_\infty$ instead.
This link shows that there is a kronecker delta function in matlab. However:
>> help kroneckerDelta
kroneckerDelta not found
I am using R2011b, so maybe this wasn't programmed into the toolkit yet?
EDIT:: It works in MuPad, just not in matlab...
.
The Kronecker delta returns 1 if j==k...
So you could simplify the expression with:
function d=kronDel(j,k)
d=j==k
end
Luckily, MATLAB represents booleans as (0,1)
I don't see it in my R2012b so perhaps not. Unless you need the symbolic math, you could always write your own. Something as simple as
function d = kronDel(j,k)
if j == k
d = 1;
else
d = 0;
end
You can also do this inline, like
( a == b )
However, using an anonymous function is a nice way to convert a one liner like this into something that is more readable
kronDel = #(j, k) j==k ;
kronDel( 2, 1 )
kronDel( 2, 2 )
Your link to is to the MuPAD function kroneckerDelta -note the URL and the funky typography of the examples. You won't see it in any version of Matlab because it's only available through MuPAD (type mupad in your command window and try in the window that launches). I have no idea when it was added to MuPAD, I know that it's at least in R2012b. You may have it even if the help command returns nothing.
If you have kroneckerDelta in R2011b, you won't be able to run it from the regular command window or Editor in the normal fashion.
evalin(symengine,'kroneckerDelta(1,1)')
or the more flexible
feval(symengine,'kroneckerDelta',1,1)
See more here. However, if you're not working with symbolic math, there's really no reason to use this function that I can see -it's not even vectorized! I'd go with a solution that fully emulates kroneckerDelta's behavior in double precision:
function d=kronDel(m,n)
if nargin == 1
d = double(m==0);
else
d = double(m==n);
end
Assume that I have some array of data (a vector to be specific).
Can I plot it element by element sequentially using Gnuplot such that it seems as if it is a real life signal that is being traced through a monitor?
I know that I can write the whole data into a text file using Common Lisp, then using gnuplot I can plot it in a batch format. What I require is that I want to put a point on my plot as data comes sequentially.
Data will probably be generated inside a loop, thus you may consider x-axis as the integer valued discrete-time axis. So in the loop if the first element of the array is generated as 5, I would like to put a point on my plot to (0,5). Then if the second element is generated as 3, I would like to put another point on my plot to (1,7) (preserving the old data point). So as I iterate through the loop, I plot the data sequentially.
I am using emacs and Common Lisp for my purposes and I want to plot this data staying within these tools. If there are any other options other than Gnuplot, I would like to hear them.
If this is not easily possible, it would be cool, if I can run a Gnuplot command file by some Common Lisp command.
edit:
Following advices people gave under this thread, I wrote a code using cgn which uses ltk.
Right now I open two x11 windows at pre-specified positions on my screen and I enter the loop. In loop each time I open a stream and write the data (sine and cosine waves of 0.25 Hz sampled at 20 Hz) to the text file trial.txt with the :if-exists :append option and close the stream. Then at each iteration I plot the whole data using the gnuplot through the format-gnuplot command. This code gives me two windows of pre-specified x and y ranges and then one can watch the evolutions of aforementioned sine and cosine waves in the windows.
As I have stated before I don't have strong programming background (I am an electrical engineer who somehow ended using common lisp) and I am pretty sure that my code is non-optimal and unelegant. If you guys have some further advices, corrections etc. I would really like to hear them. The code is here:
(setf filename "trial.txt")
(setf path (make-pathname :name filename))
(setf str (open path :direction :output :if-exists :supersede :if-does-not-exist :create))
(format str "~,4F ~,4F" -1 -1)
(close str)
;start gnuplot process
(start-gnuplot "/Applications/Gnuplot.app/Contents/Resources/bin/gnuplot")
;set 2 x11 windows with the following properties
(format-gnuplot "cd ~S" "Users/yberol/Desktop/lispbox/code")
(format-gnuplot "set terminal x11 0 position 0,0")
(format-gnuplot "set xrange [0:10]")
(format-gnuplot "set yrange [-1:1]")
(format-gnuplot "unset key")
(format-gnuplot "set grid")
(format-gnuplot "plot ~S using 1" filename)
(format-gnuplot "set terminal x11 1 position 800,0")
(format-gnuplot "plot ~S using 2" filename)
;write data into text
(loop :for i :from 0 :to 10 :by (/ 1 20) :do
(setf str (open path :direction :output :if-exists :append :if-does-not-exist :create))
(format str "~,4F ~,4F ~,4F ~%" i (sin (* 2 pi (/ 5 20) i)) (cos (* 2 pi (/ 5 20) i)))
(close str)
(format-gnuplot "set terminal x11 0")
(format-gnuplot "plot ~S using 1:2 with lines" filename)
(format-gnuplot "set terminal x11 1")
(format-gnuplot "plot ~S using 1:3 with lines" filename)
(sleep 0.1))
(close-gnuplot)
Thank you very much.
cgn is a working Common Lisp solution for interfacing with gnuplot, which uses LTK
You could create process to gnuplot and send data to it's stdin along with plotting commands. I'm not sure how to manage such process in Common Lisp but you definitely can do this in Emacs:
(setf *gnuplot-proc* (start-process "gnuplot" "*gnuplot-proc*" "gnuplot"))
;;; initiate plotting of data from stdin
(process-send-string *gnuplot-proc*
"plot \"-\" with lines\n")
;; send your data
(process-send-string *gnuplot-proc*
"5 -1\n4 -3.5\n3 9.5\n")
;; end of data, after this gnuplot would pop up interactive window
(process-send-string *gnuplot-proc* "e\n")
With such asynchronous process it's easy to write something to make it interactively update plot as new data comes along.
You might have a look at the orgplot mode, which ties gnuplot into emacs org tables.
http://orgmode.org/worg/org-tutorials/org-plot.html
You could use eazy-gnuplot, I do. See it here: eazy-gnuplot examples. The github repo is here: github repo. I don't have more time to provide an example here, sorry.
I am not experienced with Gnuplot, and a quick search didn't turn up too much information. But perhaps i can propose an approach. Say you chunk your input, for example '(1 2 3 4 5) would be '((1) (1 2) (1 2 3) (1 2 3 4) (1 2 3 4 5)), you can then generate a plot for each, and use a graphics library like lispbuilder-sdl to display it in a window with a time delay. SDL has a timer and it can display images just fine.