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

조회 수: 2 (최근 30일)
Mohammad Kaif
Mohammad Kaif 2020년 10월 27일
답변: Vedant Shah 2025년 2월 18일
%% 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