Maxima: How to turn all coefficients of a polynomial positive - symbolic-math

For a maths project I am currently using the CAS Maxima (wxMaxima). As the project is almost finished I would like to remain with Maxima, but there is one problem left:
The issue is that I have to convert a certain polynomial P by making all its coefficients positive. I.e. adding up the absolutes of all coefficients (but not taking the absolute value of the whole polynomial), for example
P(...)=-15x^3+3y^2-4x^2
turns to
P'(...)=15x^3+3y^2+4x^2
I could not find an implemented function that would help me with this. And could not find a solution by implementing it with a map function. Do you know a way to solve this issue?
Thank you for your help!
Jonas

You can calculate a sum of absolute values:
P:-15*x^3+3*y^2-4*x^2;
P2:sum(abs(args(P)[i]),i,1,length(args(P)));
>> 3*y^2+15*x^2*abs(x)+4*x^2
(unfortunately, here is abs(x) but you can use subst(x,abs(x),P2))
The same with map:
P2:map(abs,P);
Or convert an expresstion to string and replace "-" to "+":
s:string(P);
s2:ssubst("+","-",s);
P2:eval_string(s2);
>> 3*y^2+15*x^3+4*x^2

Related

I'm trying to interpolate and find the minimum x of the interpolation in C (Possibly with secant method)

I want to create my own C function to interpolate some data points and find an accurate minimum (Overall project is audio frequency tuning, and I'm using the YIN algorithm which is working well). I am implementing this on a digital DSP K22F ARM chip, so I want to minimize floating point multiplies as much as possible to implement within the interrupt while the main function pushes to a display and #/b indicators.
I have gotten to the point where I need to interpolate I have implemented the algorithm, found the integer minimum, and now need to interpolate. Currently I am trying to parabolically interpolate using the 3 points I have. I have found one that works within a small margin of error Most interpolation functions seem to only be made between two points.
It seems as though the secant method on this page would work well for my application. However, I am at a loss for how to combine the 3 points with this 2 point method. Maybe I am going about this the wrong way?
Can someone help me implement the secant method of interpolation?
I found some example code that gets the exact same answer as my code.
Example code:
betterTau = minTau + (fc - fa) / (2 * (2 * fb - fc - fa));
My code:
newpoint = b + ((fa - fb)*(c-b).^2 - (fc - fb)*(b-a)^2) / ...
(2*((fa-fb)*(c-b)+(fc-fb)*(b-a)))
where the x point values are a, b, and c. The values of each point is fa, fb, and fc, respectively
Currently I am just simulating in MATLAB before I put it on the board which is why the syntax isn't C. Mathematically, I am not seeing how these two equations are equivalent.
Can someone explain to me how these two functions are equivalent?
Thank you in advance.

Different solutions while integrating stiff equation

I am trying to integrate Rosenzweig-MacArthur model (equations) using Backward Differentiation Method using CVODE in C for stiff equations. I have to specify tolerance value for integration. Depending on the tolerance value I give, I get different solutions. I am not able to see which one is the correct solution. Can you please tell me what should (criteria for choosing) the tolerance value be?

How to determine odd number from a displayed sequence in C?

I would like to determine the odd numbers from a given sequence of numbers. After determining,I want to display those odd numbers.
Can you help me?
I can only use loops,if-elseif-else,swtich,break and continue. Anything beyond the said lessons are not allowed.
Thank you.
P.S
I am sorry if I cannot provide the code. I want to code it on my own.I just need some ideas from you.
Steps:
Loop through the array(sequence) element by element
If an array_element%2 is one, display the number.(% is the modulus operator and gets the remainder of the division of its operands)
Now just convert the above steps into code.

how to find derivative of an array of numbers

I need help in finding derivative of single array consisting on [1111222221111122222]
need how to get derivative of 1, -1 and 0 from above ? iam using numpy. i need some help in logic
I don't know the problem in detail, but maybe you can use numpy.diff or numpy.gradient.

How does the bwarea function of matlab work and how can I implement it in C?

I want to understand the working of the bwarea function of MATLAB. Also I want to implement this function in C. Any idea about how to implement will be very helpful.
Also is there a substitute for bwarea in opencv?
Thanks.
The manual suggests to examine the pixels by 2-by-2 neighbours.
These neighbours can take 6 different patterns which I tried to picture here. Examining each and every 2-by-2 neighbour and calculating the total is how bwarea works.

Resources