What numerical method should i use for the given example? - scilab

PROBLEM: We have partial difference equation u(t): du/dt=sin(t); u(0)=0.
What numerical method should I use to solve the equation, how would i write an algorithm for u(1)?
I thought I could try finite difference method but I could use some guidance.

Please give a look at the ode function

Related

How can I define a function in the form of f(a;b) in R?

This has been a recurring problem for me, so I'll have to address it here.
I'm trying to build a non-linear optimization problem using optim or fsolve, and I need certain variables as fixed parameters.
So by f(a;b), I mean a function that defines b as given, and immovable for the optimization.
Evidently matlab has a way to define b as just a parameter set & only allow a to be moved in the optimization; in R this doesn't seem to apply in the same way as matlab. Both optim & fsolve require that I specify the initial values of both a & b, and they calculate the results shifting b as well as a.
If anyone could let me know of a good way out of this that would be much appreciated.
Thank you!
You can pass b via the ... argument of optim.

Exponential Integral in Julia

I am looking for an alternate function of scipy.special.expi() in julia. This function finds exponential integral Ei. More details can be found here: https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.expi.html
Please suggest a solution to this issue.
Thanks in advance!
It looks like https://github.com/JuliaMath/SpecialFunctions.jl has an implementation.
As suggested by #Oscar, the equivalent alternative to scipy.special.expi() in julia can be implemented as follows:
using SpecialFunctions
#to find the exponential integral of x
expinti(x)

Logistic equation with or without brackets is correct?

I am coding a logistic function where the function reads:
Now to calculate the % chance of an event happening I have been using:
e^x/1+e^x
now my answer changes significantly depending on if I use:
e^x/1+e^x or e^x/(1+(e^x))
which of these two is correct ?
thanks
Hyflex
Precedence question. The correct, unambiguous answer is,
(e^x)/(1+(e^x))

Minimisation using the nlminb R-function

I would like to find the 4-dimensional vector that minimises some function f which depends on 4 variables. The first three variables take on strictly positive values; the fourth one is unconstrained.
To do this, I would like to use R. I have tried to apply the nlminb function with lower=c(0.001, 0.001, 0.001, -Inf) as one of its optional argument. The procedure does converge but it turns out that the proposed solution does not satisfy the constraint !
I have an alternative solution that consists of using an exponential transformation. However, I would appreciate to figure out why R returns a solution that does not meet my requirements.
Any comment will be appreciated,
Thanks,
Marco
It would be very difficult for me to provide that function here. The reason is that it depends on a number of pre-defined stuff.
Anyway, I am not sure to understand why this occurs but I have realized that my function sometimes returns NaN due to very very large numbers. Actually, I have some doubt about convergence.
On the other hand, I have made some modifications and the alternative solution seems to work well.
As a conclusion, I think that the problem came from my function, not from nlminb.
Best,
Marco

How can I estimate the logarithmic form of data points using R?

I have data points that represent a logarithmic function.
Is there an approach where I can just estimate the function that describes this data using R?
Thanks.
I assume that you mean that you have vectors y and x and you try do fit a function y(x)=Alog(x).
First of all, fitting log is a bad idea, because it doesn't behave well. Luckily we have x(y)=exp(y/A), so we can fit an exponential function which is much more convenient. We can do it using nonlinear least squares:
nls(x~exp(y/A),start=list(A=1.),algorithm="port")
where start is an initial guess for A. This approach is a numerical optimization, so it may fail.
The more stable way is to transform it to a linear function, log(x(y))=y/A and fit a straight line using lm:
lm(log(x)~y)
If I understand right you want to estimate a function given some (x,y) values of it. If yes check the following links.
Read about this:
http://en.wikipedia.org/wiki/Spline_%28mathematics%29
http://en.wikipedia.org/wiki/Polynomial_interpolation
http://en.wikipedia.org/wiki/Newton_polynomial
http://en.wikipedia.org/wiki/Lagrange_polynomial
Googled it:
http://www.stat.wisc.edu/~xie/smooth_spline_tutorial.html
http://stat.ethz.ch/R-manual/R-patched/library/stats/html/smooth.spline.html
http://www.image.ucar.edu/GSP/Software/Fields/Help/splint.html
I never used R so I am not sure if that works or not, but if you have Matlab i can explain you more.

Resources