Can somebody tell me how to implicitly differentiate equations in Scilab?
Example:
x^2+y^2=25
(a circle equation)
The derivative is:
dy/dx=−x/y
How can we accomplish this implicit differentiation in Scilab?
May be with diff or dassl or another function of Scilab?
Scilab is oriented to numerical computations. You can go to http://www.wolframalpha.com and type "differentiate x^2 + y^2 = 25 in x" into the input box.
Related
I am trying to solve two equations below for my project. I was unable to find any straightforward guide to solving the differential equations.
I am trying to plot a graph of h over time for the equations with a given initial h, miu, r, theta, g, L, and derivatives of h and theta wrt t. Is this possible? And if so, how?
The two equations mentioned
I tried to type the equations into Octave with the given conditions, but there seems to be an error that I am unable to identify.
Whatever is the numerical software you will use, Octave or another one (that does not formal calculation), the first step is to transform your system or N coupled Ordinary Differential Equations (ODEs) of order p into a system of p*N coupled ODEs of order 1.
This is always done by setting intermediate derivatives as new variables.
For your system, then
will become
Then, with Octave, and as explained in doc lsode you define a function say Xdot = dsys(X), that codes this system. X is the vector [h, theta, H, J], and Xdot is the returned vector of their respective derivatives, as defined by the right hand expressions of the system of first order ODEs.
So, the 2 first elements of Xdot will be trivial, just Xdot=[X(3) X(4) ...].
Of course, dsys() must also use the parameters M, g, m, µ, L, and r. As far as i understand, they can't be passed as additional arguments to dsys(). So you must defined them before calling lsode.
For initial states, you must define the vector X0=[h0, theta0, H0, J0] of known initial values.
The vector of increasing times >= 0 to which you want to compute and get the values of X must then be defined. For instance, t = 0:100. 0 must be the first element of t.
Finally, call Xt = lsode(#dsys, X0, t). After that you should get
Xt(:,1) are the values of h(t)
Xt(:,2) are the values of theta(t)
Xt(:,3) are the values of H(t)=(dh/dt)(t)
Xt(:,4) are the values of J(t)=(dtheta/dt)(t)
After a process usyng the SymPy in Julia, I generated a system of nonlinear equations. For the sake of simplicity, I am going to put an approximation here for the case of just a non-linear equation. What I get is something like this equation:
R = (p) -> -5.0488*p + p^2.81 - 3.38/( p^(-1.0) )^2.0
I can plot the R function
using Plots
plot(R, 0,8)
We can see that the R function has two zeros: p = 0 and 5.850< p < 8.75. I would like to find the positive zero. For this, I tryed the nlsolve function but with error:
using NLsolve
nlsolve(R , 5.8)
MethodError: no method matching nlsolve(::var"#1337#1338", ::Float64)
Closest candidates are:
nlsolve(::Any, ::Any, !Matched::AbstractArray; inplace, kwargs...)
First, Where am I going wrong with the nlsolve function?
If possible, I will appreciate a solution using SymPy package in Julia.
This question has been answered on the Julia discourse here: https://discourse.julialang.org/t/find-zero-of-a-nonlinear-equation-using-julia/61974
It's always helpful to cross-reference when asking on multiple platforms.
For reference, the solution was
using NLSolve
function R(F,p) #p is a vector too, not a number
F[1] = -5.0488*p[1] + p[1]^2.81 - 3.38/( p[1]^(-1.0) )^2.0
end
nlsolve(R , [5.8])
So I want to ask whether there's any way to define and solve a system of differential equations in R using matrix notation.
I know usually you do something like
lotka-volterra <- function(t,a,b,c,d,x,y){
dx <- ax + bxy
dy <- dxy - cy
return(list(c(dx,dy)))
}
But I want to do
lotka-volterra <- function(t,M,v,x){
dx <- x * M%*% x + v * x
return(list(dx))
}
where x is a vector of length 2, M is a 2*2 matrix and v is a vector of length 2. I.e. I want to define the system of differential equations using matrix/vector notation.
This is important because my system is significantly more complex, and I don't want to define 11 different differential equations with 100+ parameters rather than 1 differential equation with 1 matrix of interaction parameters and 1 vector of growth parameters.
I can define the function as above, but when it comes to using ode function from deSolve, there is an expectation of parms which should be passed as a named vector of parameters, which of course does not accept non-scalar values.
Is this at all possible in R with deSolve, or another package? If not I'll look into perhaps using MATLAB or Python, though I don't know how it's done in either of those languages either at present.
Many thanks,
H
With my low reputation (points), I apologize for posting this as an answer which supposedly should be just a comment. Going back, have you tried this link? In addition, in an attempt to find an alternative solution to your problem, have you tried MANOPT, a toolbox of MATLAB? It's actually open source just like R. I encountered MANOPT on a paper whose problem boils down to solving a system of ODEs involving purely matrices.
Linear functions in mathematics are those polynomials whose degree is 1 and hence they are straight in nature when plotted on a graph. But the constant functions like f(x) = 3, even though their degree is 0, are straight in nature when plotted on a graph. Can’t we call them linear?
I would say they are not. There is some confusion between the equation of a straight line and the concept of linearity.
A linear function is additive, i.e. f(x+y) = f(x)+f(y), which is not true for a constant function.
The equation of a straight line through the origin y = m.x is indeed linear, but the equation of a general line y = m.x + p is not.
A linear function with an additional constant is called affine. Hence a constant function is affine.
There are both opinions, however claim of Yves Daoust is simply wrong. Consider
<i>f(x) = 2x +5 </br>
f(2) = 9</br>
f(3) = 11</br>
f(5) = 15</i>
which is definitely not 20...
I'm trying to input a second order differential equation to solve into matlab over x = 0 to x =1. I can't figure out how. Here's the equation:
y'' = 1 + 0.1 \sqrt{1+(y')^2}
with initial conditions at zero.
Normally you solve higher-order equations by converting to a system of first order equations. Here, you would define:
y' = v
v' = 1 + 0.1 \sqrt{1 + v^2}
Define a function computing the right-hand side, and use ode45.
Note that this equation is solvable without much trouble in closed form, too, so should be a good test for how to do it.