Skip to content

Commit

Permalink
Merge pull request #305 from SciML/CJM-docs_quickfix
Browse files Browse the repository at this point in the history
Cjm docs quickfix
  • Loading branch information
AlCap23 authored Nov 8, 2021
2 parents 2acf74a + 8dcb465 commit 2b809b8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
24 changes: 14 additions & 10 deletions docs/src/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,28 @@ Here is an outline of the required elements and choices:
## Basic usage

```julia
using DataDrivenDiffEq, ModelingToolkit
using DataDrivenDiffEq, ModelingToolkit, LinearAlgebra

# The function we are trying to find
f(u) = u^2 + 4u + 4
X = f.(1:100) # Generate data
X = reshape(X, length(X), 1) # Reshape into a matrix

f(u) = u.^2 .+ 2.0u .- 1.0
#
X = randn(1, 100)
Y = reduce(hcat, map(f, eachcol(X)))
# Create a problem from the data
problem = DiscreteDataDrivenProblem(X)
problem = DirectDataDrivenProblem(X, Y)

# Choose a basis
@variables u[1:1]
using Symbolics: scalarize
u = scalarize(u)
basis = Basis(monomial_basis(u, 2), u)
@variables u
basis = Basis(monomial_basis([u], 2), [u])
println(basis)




# Solve the problem, using the solver of your choosing
res = solve(problem, basis, STLSQ())
println(res)
println(result(res))
```

## Defining a Problem
Expand Down
3 changes: 2 additions & 1 deletion src/solution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ function build_solution(prob::DataDrivenProblem, Ξ::AbstractMatrix, opt::Optimi
retcode = size(Ξ, 2) == size(prob.DX, 1) ? :success : :incomplete
pnew = !isempty(parameters(b)) ? [prob.p; ps] : ps
X = get_target(prob)
Y = res_(prob.X, pnew, prob.t, prob.U)
x, _, t, c = get_oop_args(prob)
Y = res_(x, pnew, t, c)

# Build the metrics
sparsity = norm(Ξ, 0)
Expand Down

0 comments on commit 2b809b8

Please sign in to comment.