Solving a differential equation
古いコメントを表示
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
採用された回答
その他の回答 (1 件)
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.
2 件のコメント
Simone
2022 年 11 月 28 日
Davide Masiello
2022 年 11 月 28 日
Maybe your data was already arranged in columns, in which case you need to delete the apostrophe after C and V in the fit function.
カテゴリ
ヘルプ センター および File Exchange で Linear Algebra についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!