Able to get energy from force displacement data (by integration, used trapz) but unable to get force from energy data?
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello everyone, I have force (Force_data), displacment (disp_data), energy data (Energy_data) attached in excel file.
To get energy using matlab from force and dispalcement data, I did integration of force over displacment using matlab code where I have used trapz to get energy. And energy calculated using matlab is matching with Energy_data.
filename_1 = ['Force_data_X'];
force = xlsread(filename_1,'Sheet1');
filename_2 = ['disp_data'];
disp = xlsread(filename_2,'Sheet1');
iteration = length(force)
for i =2:iteration
x_trap = disp([1:i],1);
y_trap = force([1:i],1);
q_trap(i,1) = trapz(x_trap, y_trap); % gives integral energy equivalent to Energy_data and matches exact
end
But if I do derivative of energy with disp data to get force (caluclated using matlab), force is not matching and differs vary significantly.
I did polyfit with 2 degree of polynomial but force is not matching with Force_data (excel data).
Any way that I can calculate force from energy.
Thanks,
Ankit
0 commentaires
Réponses (1)
Akash
le 24 Jan 2024
Hi Ankit,
To derive the "force" from the "energy" and "displacement data", you can use the "gradient" function. The "gradient(A, B)" function computes the gradient of data "A" with respect to data "B", essentially giving the rate of change of "A" for each corresponding increment in "B".
You can utilize the below provided code snippet that demonstrates how you can apply the "gradient" function to the provided "displacement" and "energy" data to compute the "force":
% Load the force and displacement data from the Excel file
force_data = xlsread('Force_data.xlsx');
disp_data = xlsread('disp_data.xlsx');
iteration = length(force_data)
% Calculate energy from force and displacement
for i =2:iteration
x_trap = disp_data([1:i],1);
y_trap = force_data([1:i],1);
energy(i,1) = trapz(x_trap, y_trap);
end
% Calculate the force from energy and displacement
force_calculated = gradient(energy, disp_data);
% Calculate error metrics
rmse_value = sqrt(mean((force_data - force_calculated).^2));
disp(rmse_value);
% Plot the original force data and the calculated force
plot(disp_data, force_data, 'b', 'LineWidth', 2);
hold on;
plot(disp_data, force_calculated, 'r--', 'LineWidth', 2);
xlabel('Displacement');
ylabel('Force');
legend('Original Force', 'Calculated Force');
For more information regarding "gradient" function, please refer to the below provided documentation link.
I hope this helps
0 commentaires
Voir également
Catégories
En savoir plus sur Numerical Integration and Differentiation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!