Solving a differential equation
4 views (last 30 days)
Hello everybody, I can't seem to find a way to solve the following differential equation.
I have an array for V (which is my indipendent variable) and C (which is the dependent one), I need to find a punctual value of N for each value of C and V.
Looking online I've tried to use this line of code
ode = y == ((C).^3)/(k)*diff(V,C)
But I get the error : Error using diff Difference order N must be a positive integer scalar
Bjorn Gustavsson on 28 Nov 2022
According to your description you don't have a differential equation if you have the values of C and the known dependent values in V, and you want the values of N according to your equation. The best you can do from this is simply:
N = C^3/k*gradient(V,C);
More Answers (1)
Davide Masiello on 28 Nov 2022
Since you have data for V and C you could fit them with the analytical solution of the differential equation.
Let's assume this is your dataset
k = 10;
C = [1 2 3 4 5 6 7 8 9 10];
V = [0.0158 11.3471 13.4291 14.1110 14.4800 14.5975 14.7361 14.8572 14.8940 14.9459];
Let us also assume that the initial condition is v(c=1) = 0.
You can find the analytical solution to the differential equation for a generic N.
syms x y(x) N
myode = diff(y,x) == N*10/x^3;
sol = dsolve(myode,y(1) == 0)
Then, turn the symbolic solution into an anonymous function.
f = matlabFunction(sol)
And finally fit the function to the data
fitobj = fit(C',V',f,'StartPoint',1)
The result is N = 3.015, which is good considering that I had produced the fake C and V data by using N = 3 and adding a bit of random noise.