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

1 回表示 (過去 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));
  2 件のコメント
Mohammad Kaif
Mohammad Kaif 2020 年 10 月 27 日
Mohammad Kaif
Mohammad Kaif 2020 年 10 月 27 日
This is the question.

サインインしてコメントする。

回答 (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 Center および File ExchangeMATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by