I am trying to use NEQNF to solve a system of 6 non linear equations. I need to determine 2 variables to solve my system. According to description i need to define "N" which is the length of "X"(variables) AND "F"(equations).
Does this mean that i can use this solver only if X=F? Because N is defindes as an integer in the example given below in the description.
Or can i define N as a vector? How does declaration of N supposed to look like in this case?
From the link you gave:
X – The point at which the functions are evaluated. (Input) X should
not be changed by FCN.
F – The computed function values at the point X. (Output)
N — Length of X and F.
X and F are vectors of length N (scalar!). X is the input to FCN, and F the output. So I would guess that F is (generally) not equal to X.
Related
Why doesn't sympy divide this polynomial?
>>> import sympy as sp
>>> x,y = sp.symbols("x y")
>>> print(sp.div(y+x,y))
(0, x + y)
I was expecting the answer to be (1,x) because the quotient is 1 and the remainder is x. How can I get sympy to divide polynomials?
What I want is to express some polynomial p as p=aq+r where r is the remainder and q is the quotient and a is the divisor. In the example above, notice that y+x=1*x+y and so it seems to me that we should be able to find that 1 is the quotient of p by x.
some more details
Say I am working over a real multivariate polynomial ring, and say I want to express some polynomial p as p=aq+r for some non zero polynomial a and for some r with deg(r)<deg(q). By degree (deg) I mean total degree, that is, the degree of the single variate polynomial that you get when you substitute all variables with x. For example, the total degree of xy^2 is 3. Although such a pair (q,r) may not exist, if it does exist, it is unique given (p,a). Here is a proof:
Say p=aq+r and p=aq'+r' for some r st. deg(r)<deg(a) and assume q≠q'.
By subtracting these equations and rearranging we have a(q-q')=r'-r.
Notice that because q-q'≠0, we have deg(a)≤deg(a(q-q'))=deg(r-r').
Thus because deg(r)<deg(a), we may conclude that deg(a)≤deg(r').
Thus if there exists such an r, this r is unique.
I point this out so as to suggest that the computation I am asking for is well defined.
It seems to me that being able to do multivariate polynomial division is a natural feature
that sympy should support. If I am wrong here, please let me know why.
See here
Given a family (𝑥𝑖) of symbols, or other suitable objects, including numbers, expressions derived from them by repeated addition, subtraction and multiplication are called polynomial expressions in the generators 𝑥𝑖.
You need to specify the generators. Because given the expression y+x, the machine can NOT figure out which variable is the generator. It can be f(y) = x+y or f(x) = x+y.
You need to tell it the order of generators is [x,y].
print(sp.div(y+x, y,gens=[x,y]))
# (0, x + y)
If you set the order of generators to be [y,x].
print(sp.div(y+x, y,gens=[y,x]))
# (1, x)
Is it possible to write a C++ function like if we enter 9 then the program return 6 and if we input 6 the program return us 9 as output? Without using any conditional statement?
You are asking for functions that satisfy:
f(x) = y
f(y) = x
for some fixed x and y.
You can look for involutions, which are functions that satisfy:
f(f(x)) = x
Search for those that you can implement without conditionals, which usually means using only integers and the built-in arithmetic operators.
For instance, XOR:
f(x) = x ^ N
for some fixed N that you adjust using the given x/y.
I would like to write a function in OCaml that will calculate the definite integral for the given function. The problem is that I aim for the following syntax:
let sphere r phi theta = r *. sin phi *. cos theta in
let dphi = 10 in (* number of parts *)
let dtheta = 10 in (* number of parts *)
let zero = 0.0 in
let two_pi = 2.0 *. 3.14159
in
integral zero two_pi (integral zero two_pi (sphere 3.0) dphi) dtheta
The problem is that using rule like trapezoidal rule I need to write something like:
0.5 *. (f a +. f b) *. d
Which expects that the f a and f b are not partially applicated functions.
I don't expect that the result from the last integral function call will return me a float number, I'm totally fine with some functional.
I've realized that the question is very unspecific. Let me restate it in a more general way:
I have a function float->float->float which after the application of integral function should give me float->float. It should be general, so the integral of float->float should result in float.
The problem is that I need subtract two functions of the same order: f(a) -. f(b), where both of them could be float->float->float, float->float or even float->float->float.
To decrease the order of a function I need a signature like: (float->'a->float) -> ('a->float).
Is this even possible? Specifically in OCaml?
The more I think about this problem of having one function calculating the integral that can be chained, the more it seems like an impossible task/stupid way to do it.
In fact I've implemented this but using my own data type (called function_type which can be Scalar3rdOrderFunction, Scalar2ndOrderFunction, Scalar1stOrderFunction, Scalar0thOrderFunction). But for the prize of polymorphism the compiler cannot warn me when I try apply the integral three times for function float->float->float.
I'm trying to figure out how to implement fixed point iteration in Ocaml. That is, given a function f and an x, I want to calculate what the final value of what f(f(f(x)...)) will be.
So for example, if my function is x/2 and my x=50, my answer should be 0.
So far, I have
let rec computed_fixed_point eq f x =
if (x == f x) then
x
else
computed_fixed_point eq f (f x)
This works for the function x/2 and x=50 (giving me 0), but for functions that go off to infinity or something other than 0, it doesn't seem to work.
Can another give me some advice? Thanks!
It's a little hard to understand the rationale of this problem. Not every function is going to have a fixed point. For example fun x -> (x + 1) mod 5. Not every function with a fixed point will reach the fixed point by repeated application from a distinct starting point. (I just did some googling, and fixed points like this are called "attractive fixed points".)
Here are some comments:
You shouldn't use ==, which is the physical equality operator. You possibly want to use =, equality of values.
However, I don't see what the eq parameter is for. Perhaps the caller is allowed to specify what equality to use. If so, you should use this instead of ==.
How can I calculate the length of a list
?- size_sub([[b,a,g], [9,3,7,4], [6]], X).
X = [3, 4, 1].
?- size_sub([[c,g,e,w], [7]], X).
X = [4, 1].
?- size_sub([], X).
X = [].
Ok you need to start with the base case which is the last answer
so size_sub([],X). is true if X=[] so first you write that as a rule.
size_sub([],[]).
Then you need to do the inductive step a list that is one longer than the previous. I am going to assume that you have a size/2 function for determining the size of a single list (if not please comment).
So the inductive step is going to operate on the length of the first parameter so N->N+1. We would represent this by striping off the head of the list syntax will be [H|T] now the second parameter (your answer) is going to be the length of H with the result of calling size_sub on T. As we cannot specify rules in the parameters in the header we will use N to represent the length of H and T2 to represent the result of size_sub on T.
So the first part of the rule becomes size_sub([H|T],[N|T2]):-
now we follow it with the predicates that will assert the values for N and T2.
size(H,N),
size_sub(T,T2).
putting that all together you get
size_sub([],[]).
size_sub([H|T],[N|T2]):-
size(H,N),
size_sub(T,T2).
size/2 is a far simpler case and following the same process of base + inductive you should be able to create the rules for it. Please comment if you need further help.
** EDIT - Request for size/2 definition **
To define size/2
Start with the base case, the empty list has a size of 0.
size([],0).
Now the inductive step. The size of list of length(N+1) is the size of a list of length(N). So lets define our list as [_|T] I've defined the list using _ to represent the head because we never use it so we can just use the anonymous variable. Lets use N to represent the length of T, and M to be N+1.
so
size([_|T],M):-
now lets define N
size(T,N),
and finally assert that M is equal to N + 1
M is N+1.
so putting everything together
size([],0).
size([_|T],N):-
size(T,M),
N is M+1.
size_sub([],[]).
size_sub([H|T],[N|T2]):-
size(H,N),
size_sub(T,T2).
To map length/2 over a list of lists, we can use the meta-predicate maplist/3 like this:
size_sub(Xss,Ls):-
maplist(length,Xss,Ls).