-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't figure out how to create multivariate approximation #330
Comments
I think you can make your example work if you use set_variables("x", order=7, numvars=4) # numvars is just the number of variables wrt which you're expanding Probably it makes sense to add a comment about this in the docs? |
Thanks for the help, the following does work function dxf(xt, ut)
[
xt[3]
xt[4]
-0.8333333333333334((0.1(0.9810000000000001sin(xt[2]) - 0.08333333333333334(-ut[1] - 0.1(xt[4]^2)*sin(xt[2]))*cos(xt[2]))*cos(xt[2])) / (0.008333333333333335(cos(xt[2])^2) - 0.05) - ut[1] - 0.1(xt[4]^2)*sin(xt[2]))
(0.9810000000000001sin(xt[2]) - 0.08333333333333334(-ut[1] - 0.1(xt[4]^2)*sin(xt[2]))*cos(xt[2])) / (0.008333333333333335(cos(xt[2])^2) - 0.05)
]
end
nx = 4; nu = 1
set_variables("x", order=7, numvars=nx+nu)
taylor_expand(zeros(nx+nu); order=7) do xu
xs = xu[1:4]
us = xu[5]
dxf(xs, us)
end Is there an interface available that does not mutate a global state, like I assume EDIT: Actually I had a mistake in the code above, it still does not work: function dxf(xt, ut)
[
xt[3]
xt[4]
-0.8333333333333334((0.1(0.9810000000000001sin(xt[2]) - 0.08333333333333334(-ut[1] - 0.1(xt[4]^2)*sin(xt[2]))*cos(xt[2]))*cos(xt[2])) / (0.008333333333333335(cos(xt[2])^2) - 0.05) - ut[1] - 0.1(xt[4]^2)*sin(xt[2]))
(0.9810000000000001sin(xt[2]) - 0.08333333333333334(-ut[1] - 0.1(xt[4]^2)*sin(xt[2]))*cos(xt[2])) / (0.008333333333333335(cos(xt[2])^2) - 0.05)
]
end
nx = 4; nu = 1
xu = set_variables("x", order=7, numvars=nx+nu)
xs = xu[1:4]
us = xu[5]
dxf(xs, us) julia> dxf(xs, us)
4-element Vector{TaylorN{Float64}}:
1.0 x₃ + 𝒪(‖x‖⁸)
1.0 x₄ + 𝒪(‖x‖⁸)
1.9620000000000002 x₂ + 1.0 x₅ + 𝒪(‖x‖²)
- 23.544 x₂ - 2.0 x₅ + 𝒪(‖x‖²) |
Actually, the problem in this case might be that the multivariate Taylor expansion is the wrong tool for this job, and what I really should be looking at is a least-squares approximation over an interval instead |
I think the problem is in the definition of nx = 4; nu = 1
xu = set_variables("x", order=7, numvars=nx+nu)
xs = xu[1:4]
us = xu[5:5] # construct us as a 1-element Vector{TaylorN{Float64}}
dxf(xs, us) then your example should work. You can also redefine |
To answer your other question, TaylorSeries.jl mutates a global state (hash-tables) to construct |
Thanks, I just figured this out as well (after a lot of trial and error). I opened #331 about this since it's kind-of a violation of the |
The way |
Hi guys, I'm trying to figure out how to create a multivariate approximation to a nonlinear function
dfx
, but can't quite understand the multivariate interface. Below is an attempt at creating an order 7 approximation, but the two nonlinear equations get approximated linearly only. What am I doing wrong?The text was updated successfully, but these errors were encountered: