What is wrong with this code?

alpha1=0.1;
eps=0.05;
gamma=0.34;
x1=0.5;
x2=0.8;
bheta1=0.11;
k1=0.65;
f=@(x1)[(alpha1-eps*gamma)x1-(alpha1/k1)(x1)^2-bheta1*x1*x2]
t=1:1000
h=integral(f,0,t)

 采纳的回答

Ameer Hamza
Ameer Hamza 2020-11-11
编辑:Ameer Hamza 2020-11-11
MATLAB does not have an implicit multiplication. You need to use * operator
f=@(x1)[(alpha1-eps*gamma)*x1-(alpha1/k1)*(x1).^2-bheta1*x1*x2];
% ^ here and ^ here
Also, It is better to vectorize the integrand; therefore, I used element-wise exponent (.^) in the expression. Also, note that 3rd input to integral() must be a scalar.

7 个评论

But I want my t value to vary from 1:1000 Is that possible?
You want to get the value of integral with all those end-points?
Yes, is that possible?
Because I want to plot graph with those values.
You can do it like this
alpha1=0.1;
eps=0.05;
gamma=0.34;
x1=0.5;
x2=0.8;
bheta1=0.11;
k1=0.65;
f=@(x1)(alpha1-eps*gamma)*x1-(alpha1/k1)*(x1).^2-bheta1*x1*x2;
t = 1:1000;
h = zeros(size(t));
for i = 1:numel(h)
h(i) = integral(f, 0, t(i));
end
plot(t, h)
Thank you so much.
I am glad to be of help!!!

请先登录,再进行评论。

更多回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by