This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
SymPy: How to return an expression in terms of other expression(s)?
Consider the following:
>>>from sympy.physics.units import *
>>>F=1*N
>>>F
kg*m/s**2
How can I force the output to be in the derived unit, N in this case?
Unfortunately, SymPy's units only work on base units, so what you want is currently impossible.
There is some work on improving the units system to allow the user to set arbitrary base units. See https://github.com/sympy/sympy/pull/1389. It is still development work, so some things might not work with it yet (and it isn't included in the main SymPy development repository yet).
Related
This question already has answers here:
Where should you put global constants in a C++ program?
(6 answers)
Closed 7 years ago.
I know this question has been answered many times and globals are bad but I have a variation. I have lots of regular expressions and I create local variables of those. Also, I have lost of strings which are constant in nature. This code is part of C++ web service. Thus this objects are getting created and destroyed all the time. Thus, I wonder if I should put them in as global inside a namespace so that I can still use them without polluting the namespace.
You might have your terminology mixed up.
By definition, variables which are in a namespace are not global. When people say "It's bad to have variables/functions/etc. defined globally", their express solution to that issue is usually to put those things in a namespace.
This question already has answers here:
Evaluating arithmetic expressions from string in C++ [duplicate]
(7 answers)
Closed 7 years ago.
i wonder if is possible, for example read a file with some content like:
a+b*c
and that my programm "create" a function to do this operation, and if i modify the file ( like a+b*c+2 ) the programm read this changes and updates what this function do. Well i dont have a solid backbround in the basis of C++ and i don't know if what i'm asking is just plain stupid. I need ( or something like this could be nice ) for my work in physics simulations, where the model is mainly definied by a equilibrium function ( and some other parameters ) so what i think is that could be good if i can make a programm to test this models without having to writte a special code for each one...
Thanks!
C++ is not interpreted code. So you can only compile hard coded expressions in source code. However you can evaluate an expression on your own. You can look at some solutions here
for sure it is "possible", actually that's what matlab, mapple or any other formal calculation software/lib do.
BTW, writing one may be quite simple if you just handle */+- basic operators, and may become more and more complex depending on what you want to use (sin cos, exp, log etc.)
Basic implementations reads of the input and build an internal tree with final values on leaves would look like soething like this in your case:
+
a *
b c
I'm sure you can find a lot of docs on it.
This question already has an answer here:
C++ class definition split into two headers?
(1 answer)
Closed 7 years ago.
Can I have a class in C++, in different .hpp files?
Because I have a class called Map which is about 5000 lines and I wonder know if I can split it in two or three files with the same class name, and if other headers will see this class like if it wasn't split.
No, you can't do that.
Besides, your class is way too big. Instead of trying to split it up lexically, consider splitting it up semantically, into multiple classes. Read about the single responsibility principle.
In short, there is a moderately serious design problem at the core of this question.
No, that's not an option. You need the entire class header in a single place to be included for. 5000 lines make me think you have code in there. You can certainly put the code from a single class in several .cpp files, just distributing your members around.
This question already has answers here:
Sharing R functionality with multiple users without exposing code [closed]
(2 answers)
Closed 8 years ago.
I am new to R.
Suppose I have an R code which takes certain real time inputs and gives output in real time.
I want to share it with a third party which uses C++ in such a way that the logic of my code is not seen but he will get output with the input he provides.
So here there are two things.
1: He uses C++ to give input
2: I have to somehow integrate my R code with his data in such a way that he can get only the output, not my logic
so my objective is two fold. One is integration with C++ and second is code protection.
How can this be done?
Simple: just write a server process that accepts incoming data via TCP and sends the responses back. Run this on a separate machine, because otherwise the client will be able to gain access to your code.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Is there any kind of “expression class” (C++)
I want to make a class that holds a function that is defined at run time.
i.e.
function function1("x*sin(3.141*x)");
I want to do things like find roots and it would be better not having to rewrite the program each time.
edit: I am looking at lua.
This thing is certainly much easier in dynamic languages. For example, in Matlab you can evaluate strings using the eval command.
However, this is not impossible in C++. You might be able to make a nice solution with a combination of C++11 lambdas and a custom interpreter. The member function can take a lambda as an argument, and you can formulate the lambda by interpreting a string.
This answer might give you a good starting point for the interpreting part of the challenge.
Evaluate Mathematical Function from String