How to integrate a function w.r.t. a variable that is not the input variable to the function
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi,
I have 2567x1 double variable which is a Strain, with a corresponding time variable.
I have a function:
function [y]=mystrainrate(reflectedstrain)
c=4980;
l_s=6*10^-3;
y=c*(reflectedstrain)/l_s;
end
I want the integral of y with respect to time between 0 and a specified time. But I want to plot it, so essentially I want a loop to find the integral up to each time index from 1 to 2567 and create another 2567x1 variable of the integrals.
But, I can't work out how to integrate a function with respect to a variable that is not the input variable to the function.
For example, I currently have this code:
for i=1:length(reflectedstrain)
nominalstrain(i,1)=integral(@mystrainrate,0,time(i));
end
But obviously this integrates the strain rate function w.r.t. the strain and not w.r.t the time.
Any help would be appreciated. Thanks.
0 Kommentare
Antworten (1)
Michael Wang
am 14 Sep. 2016
As you have mentioned, the function you are using as the input of the ‘integral’ function should be a function that w.r.t time ( i.e. y(t) or in other form y(reflectedstrain(t)) ).
The ‘ integral ’ function in this case will not work due to the relation between "reflectedstrain" and time "t" are not constant so the input function varies from time to time. I would recommend you to calculate the integral value numerically (e.g. integral_y = y (i)*delta_t ) assuming you can calculate the time difference "delta_t" between time steps.
Hope these help!
0 Kommentare
Siehe auch
Kategorien
Mehr zu Numerical Integration and Differentiation 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!