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

1 visualización (últimos 30 días)
Mohammad Kaif
Mohammad Kaif el 27 de Oct. de 2020
Respondida: Vedant Shah el 18 de Feb. de 2025
%% 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));

Respuestas (1)

Vedant Shah
Vedant Shah el 18 de Feb. de 2025
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.

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by