Octave equivalent to matlab pretty - octave

Does anybody know the octave equivalent function to Matlab's pretty. I have tried the following
symbols
x = sym('x')
diff(sin(x)*cos(x),x)
pretty (ans)

I tried pretty(ans) in octave and it did not throw an error. Also, the answer output was not enhanced. I think the function pretty is automaticly called on the output in Octave.

Related

Where is the documentation for the "end" keyword in Octave? (for indexing)

I was trying to figure out what the following Octave code does:
degree = 6;
out = ones(size(X1(:,1)));
for i = 1:degree
for j = 0:i
out(:, end+1) = (X1.^(i-j)).*(X2.^j);
end
end
I wasn't sure what the end+1 meant in Octave until I found the answer for Matlab here:
What is the `end+1` line doing here?
The accepted answer links to the Matlab official documentation which is very clear:
https://www.mathworks.com/help/matlab/ref/end.html
I'm trying to find the documentation for this same keyword in the Octave documentation but I can't seem to find it.
I've searched in the Documentation tab (Octave 5.1.0), using the function index and the search tab to no avail although I see it used in several documentation pages.
The Octave documentation, which seems to be categorized more by usage than keyword, on Index Expressions is also as explicit:
In index expressions the keyword end automatically refers to the last entry for a particular dimension. This magic index can also be used in ranges and typically eliminates the needs to call size or length to gather array bounds before indexing.
Try help end in Octave. That will give you what you're looking for.
In Octave and Matlab, there are two help-finding functions, help and doc. (doc is what pops up the GUI documentation browser.) And they will give you different results for the same topics! So always try both when you're looking for something.
And there's nothin' wrong with looking through the Matlab doco and Stack Overflow answers for this. Octave is pretty compatible with Matlab, so anything you find there for basic language functionality (except for strings, tables, and datetimes) will apply to Octave as well.

How to read in a user defined math function

I'm trying to build a program in Pascal to differentiate mathematical functions. It's working very well (calculate min/max, symmetry, drawing the graph, etc.) but I have to put the functions (i.e. x^3+3x+2) into the source code like this:
function f(x : real): real;
begin
f := x * x * x + 3 * x + 2;
end;
Though, I want the user to define the function to differentiate. Obviosly the readln function does not help.
Somebody told me the only solution would be a specific parser. But it's very difficult, and I don't know how to do it.
My idea would be to extract the function into a *.txt file for example so that it could be changed easily. Is that possible?
Can somebody show me a parser which could solve this problem or have anybody some other great solution?
I would really appreciate your help!
Thanks in advance ;)
Free Pascal ships with the symbolic package, which has both a parser and evaluator for mathematical expressions. You can probably use this as a starting point. See the documentation for usage.
There are also a number of parsers/evalutaors on SWAG:
EQUATE.PAS (short, clean evaluator)
PARSMATH.PAS (very short example code)
Math Parsing Unit (undocumented, kind of messy)
Math Evaluations (Somewhat cryptic.)
Nice Expression Parser (Small, seems well done.)
Expression Evaluator (Messier, includes trig functions.)
Math Expression Evaluator (not well documented)
Equation Parser (converts equations to arrays of coefficients)
Text Formula Parser (fairly complete parser/evaluator unit)
I bolded the ones I thought were the most useful. I don't think any of them are as complete as the symbolic package in my other answer, but they might be worth reading if you need help.
(All of this is fairly old code. Unless otherwise stated, the rule with SWAG is to treat this stuff as having a new-style BSD license)

Procedures in Gnuplot

Is there a way to have procedures (or C-like functions) in Gnuplot? I need something really simple, just something like:
function func1()
{
var1 = "string1";
var2 = var1."string2";
return var2;
}
to make my gnuplot scripts a little bit more compact.
Gnuplot supports (simple) functions with arguments:
func1(x)=x."string2"
More complicated "inline" functions can be created if you're using gnuplot 4.4:
func1(x)=(var1=x, var2=var1."string2", var1.var2) #returns x.x."string2"
In this form, the last portion of the function is what is returned (var1.var2) and the statements are evaluated left to right.
If you want to have functions which accept no parameters, you can (often) use macros:
set macro
funcmacro='"string1"."string2"'
print #funcmacro
Yes. You can concatenate strings in gnuplot with something like
strcat(str1,str2) = sprintf("%s%s",str1,str2)
str3 = strcat("string1","string2"); print str3
The first line is the function definition, the second line is just an example of usage. You can read more in the "User-defined variables and functions" section of the gnuplot documentation (it is under the "Expressions" section; you may have trouble searching for the string 'user-defined' in the pdf because of the 'fi' character generated by LaTeX).
You might want to consider looking at the Pyxplot plotting package http://pyxplot.org.uk, which has very similar syntax to gnuplot (albeit cleaned up), but which also has a lot of the features of a scripting language. It has subroutines, which should do exactly what you're asking for.

Matlab Basic Function

I'm trying to read some matlab code, but I'm new to it. How do I figure out what the input parameters are?
function [shortly, longly] = lyapunov(signal,timestep,FreqSamp,segmentapproach, duratsegmen, dodivergence)
//lots of code under here but I couldn't find out where signal, timestep, etc come from.
Read the help for lyapunov. It will tell you that information.

MATLAB integration of an anonymous function

I wanted to ask how can I can write this in MATLAB.
I want to integrate fp(z) with z(0,x). I tried this :
fpz=#(z) f1x(z) ./ quadl(f1x(z),0,1);
sol=int(fpz,0,x) --> i also tried sol=quadl(fpz,0,x)
y=solve('y=sol',x)
xf=# (y) y ; -->this is the function i want
where f1x=# (x) 1 ./(x.^2+1) and fpx = #(x) f1x(x) ./ quadl(f1x,0,1);
but it doesn't work.
Hello,thanks for helping.
The problem is that i want an analytically solution and i can't get one.
I want f1x to give me " 1/x^2+1" , fpx "4/pi*(1+x^2) and fpz "4ArcTan(x)/pi", instead of giving me "f1x=# 1./(x^2+1)"..
With the code you send me ,still the same problem.
I managed to come into this :
f1x=# (x) 1 ./(x.^2+1)
fpx = #(x) f1x(x) ./ quadl(f1x,0,1)
f2z=# (z) 1 ./(z.^2+1);
fpz=#(z) fpx(z) ./ quadl(f2z,0,1)
sol=int(fpz(z),z,0,x)
y=solve(subs('y=sol'),x)
xf=# (y) y
The "sol" and "y=" gives me analytically answer but it is wrong because i assume f1x and fpx,fpz doesn't return into analytically expressions.
0 Your definition of fpz doesn't make any sense; as Marcin already said, you're trying to integrate something that isn't a function. This shouldn't be a problem for your alternative version with f2z. I think the code in the original question should have had just f1x rather than f1x(z) in the first line.
1 Your revised version with f2z has a different problem: now in fpz you aren't actually providing the function with an argument.
The following code seems to be the kind of thing you had in mind, and works fine for me (in MATLAB R2008a, as it happens, but none of this should be different in other versions):
f1x = #(x) 1 ./ (x.^2+1);
fpx = #(x) f1x(x) ./ quadl(f1x,0,1);
fpz = #(z) fpx(z) ./ quadl(fpx,0,1);
Now evaluating fpz(3), for instance, spins for about half a second (on my old slow laptop computer) and returns 0.1273.
So I think the problems you've been having with integration of anonymous functions are just a matter of not being quite careful enough to distinguish between the function itself and a particular value of the function.
You have some further questions about the "solve" and "int" functions in the Symbolic Math Toolbox. You should take the following with a pinch of salt because I don't have that toolbox and am relying on the online documentation for it.
3 You're feeding the names of functions you've defined in MATLAB to the Symbolic Math Toolbox functions. I don't think that is supposed to work; "int" and "solve" expect explicit algebraic expressions, not MATLAB functions. (And, further, your functions all use numerical integration -- quad, quadl, etc. -- and there's no possible way that the symbolic functions can do anything useful with that.)
Finally: When you're asking questions of this sort, it's helpful if rather than "it doesn't work" you say how it doesn't work. For instance, your most recent comment is much more useful ("it gives me ..." followed by the actual output you get from MATLAB).