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

2 visualizzazioni (ultimi 30 giorni)
%% 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));

Risposte (1)

Vedant Shah
Vedant Shah il 18 Feb 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.

Categorie

Scopri di più su MATLAB in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by