Defining integration function in matlanb
16 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hannah Mohebi
am 26 Feb. 2022
Bearbeitet: Walter Roberson
am 26 Feb. 2022
I want to defin a fuction in matlab. This function is for calculating attached integral.
After defining this function I want to calculate H(T=100) in another m file.I wrote below function but it does not work.
function [H]=enthalpymethod(T)
H=int(Cp,T,[0 T]);
end
Would you please correct me.
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 26 Feb. 2022
Bearbeitet: Walter Roberson
am 26 Feb. 2022
function [H]=enthalpymethod(T)
syms T
Cp = some expression in T
H(T) = vpaintegral(Cp,T,[0 T]);
end
Now when you invoke enthalpymethod it will return a symbolic function that you can do things like fplot(H) or H(100)
Note that this will typically be less efficient than if you were to use matlabFunction() to return an anonymous function that uses integral() to do the calculations. But if Cp involves any unresolved symbol variables other than T then you need a symbolic return
0 Kommentare
Weitere Antworten (1)
Alan Stevens
am 26 Feb. 2022
Like this?
% If Cp is a constant then the integral is just Cp*T
% If it is a function of T, then define the function:
Cp = @(T) 3 + T/100; % Arbitrary function - replace with your true function
H = integral(Cp,0,100);
disp(H)
0 Kommentare
Siehe auch
Kategorien
Mehr zu Calculus 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!