How to plot an integral function(x) with limits as 10 and x.

2 次查看(过去 30 天)
%% Function that describes the integrand
Ca = 1;
V = 100;
v = 10;
k = 0.23;
r = -k*Ca;
Fao = v*Ca;
%% Funtion to solve
fp = @(Fa) -1./k.*Fa./v
fh = @(Fa) 100 - integral(fp,Fao,Fa);
%% Plot the function to estimate
c=linspace(0.0,1.0);
plot(c,fh(c));

回答(1 个)

Vedant Shah
Vedant Shah 2025-2-18
Upon reviewing the code, I identified the issue: one of the limits of the integral function is being passed as a vector, while the integral function only supports scalar limits. To compute the integral for an entire vector, it is necessary to evaluate it element by element. The MATLAB function arrayfun can be employed for this purpose. For further details, please refer to the documentation by entering the following commands in the MATLAB command line:
web(fullfile(docroot, "/matlab/ref/arrayfun.html"))
web(fullfile(docroot, "/matlab/ref/integral.html"))
To resolve the issue and ensure the code functions correctly, consider the following modification:
% Funtion to solve
fp = @(Fa) 1 ./ (-k * Fa / v);
fh = @(Fa) V - integral(fp, Fao, Fa);
% Plot the function to estimate
c = linspace(0, 1, 100);
fh_values = arrayfun(fh, c);
plot(c, fh_values);
This adjustment addresses the problem related to the integral function, allowing you to proceed with your task seamlessly.

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by