Able to get energy from force displacement data (by integration, used trapz) but unable to get force from energy data?

4 次查看(过去 30 天)
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

回答(1 个)

Akash
Akash 2024-1-24
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

类别

Help CenterFile Exchange 中查找有关 Numerical Integration and Differentiation 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by