Filter löschen
Filter löschen

Define Integral in Matlab

3 Ansichten (letzte 30 Tage)
Rim Abdallah
Rim Abdallah am 14 Dez. 2022
Bearbeitet: Fabio Freschi am 15 Dez. 2022
Hello,
If I want to write the code of this simulink model in matlab how can I do it?
x, y and z are vectors of length=6000 for each one of them.
I want to calculate the value of z at each time, I used:
for k=1:6000
func = sum(x(1:k)) - sum(y(1:k)); %x and y are discrete variables
z(k)= Constant*func*Te; %Te represents the sample time
end

Antworten (1)

Fabio Freschi
Fabio Freschi am 15 Dez. 2022
Bearbeitet: Fabio Freschi am 15 Dez. 2022
Suppose to have these data
The simulink model is calulating
you can calulate the integral in the discrete form with cumtrapz
% data
t = linspace(0,1,20).';
x = 2*t;
y = t.^2;
c = 3;
% function to integrate
dz = c*(x-y);
% function z
z = cumtrapz(t,dz);
% plot
figure,hold on
plot(t,z,'LineWidth',2)
% check
plot(t,3*t.^2-t.^3,'--','LineWidth',2)

Kategorien

Mehr zu Modeling 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!

Translated by