find unknow value to plot(best fit)
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I would like to find unknown values(D a b) below the equation.
Could you let me know what errors my code have. Finally, I am going to find the best fit curve. Thank you.
data = readtable('OO_band');
x = data.energy; %% known from data
r = data.distance; %% known from data
syms D a b; %% unknown
potential = x == D*((1-Exp(-a*(r-b)))^2 - 1);
sol = solve(potential, [D a b]);
0 Kommentare
Antworten (1)
Walter Roberson
am 19 Jan. 2023
Your x and r are vectors, so your potential is going to create a vector of equations. You are then trying to solve() that vector of equations for values of D, a, b that exactly satisfy all of the equations simultaneously . That is unlikely to work unless you happen to have exactly 3 rows in your file.
For best fit you are not looking for coefficients that solve() all of the equations exactly, you are looking for coefficients that give the least overall error, for some meaning of error . For example you might look for smallest sum of squares of error.
rng(123456)
N = 4;
x = rand(N,1) * 10;
r = rand(N,1) * 10;
syms D a b; %% unknown
model = D*((1-exp(-a*(r-b))).^2 - 1)
actual = x
residue = expand(sum((model - actual).^2))
syms AB
residueAB = subs(residue, a, AB/b)
partial_D = solve(diff(residueAB, D),D)
residue2 = subs(residueAB, D, partial_D)
symvar(residue2)
db = diff(residue2,b)
partial_b = solve(db,b)
You can see from this that pure symbolic solutions are not going to work, so ...
partial = vpasolve(db)
subs(partial_D, partial)
1 Kommentar
Walter Roberson
am 19 Jan. 2023
After which you would need to convert AB and B back to A
(The equations had exp(constant*a*b) in them a lot; I was hoping that by combining them that it might make it easier to solve for the variable, but it did not, so probably you could work more directly on the original equation after substituting in the partial solution for D.)
Siehe auch
Kategorien
Mehr zu Symbolic Math Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!