# Why I can't integrate a matrix in Matlab?

1 ビュー (過去 30 日間)
Jani 2021 年 8 月 22 日
コメント済み: Jani 2021 年 8 月 24 日
So for a while it worked, but than I ran the program again, and somehow it doesn't work again, though I did not change the code. The error message: "Attempt to execute SCRIPT integral as a function"
The code:
t=3000
a=1.044
b=-3.484*10^(-5)
k=0.0711
n=0.461
for i=1:t
MR(i)=a*exp(-k*(i^(n)))+b*i;
end
fun=@(i) MR;
MRint=integral(fun, 0, 2, 'Arrayvalued', 1)
##### 5 件のコメント表示非表示 4 件の古いコメント
Wan Ji 2021 年 8 月 23 日

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

### 採用された回答

Walter Roberson 2021 年 8 月 22 日
You saved your code into a file named integral.m which is interfering with calling MATLAB's integral() function.
for i=1:t
MR(i)=a*exp(-k*(i^(n)))+b*i;
end
After that, MR will be a vector of constants.
fun=@(i) MR;
That tells MATLAB that fun is an anonmous function that takes a single argument, and no matter what single argument is passed in, it should ignore the argument and return the content of the vector MR. It does not tell MATLAB that MR should be interpreted as a formula in i and integrated based on that formula. When you did the for i=1:t then i was given specific numeric values, 1, 2, 3, and so on, in turn, and that specific numeric value was used to calculate entries for MR.
You could integrate the vector of numeric values with respect to t, but the result is just going to be the numeric values times the difference in times.
##### 5 件のコメント表示非表示 4 件の古いコメント
Jani 2021 年 8 月 24 日
Okay, Thank you for the explanation!

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

### Community Treasure Hunt

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

Start Hunting!

Translated by