Using an integral in a for loop in matlab

2 ビュー (過去 30 日間)
Stephen Bratz
Stephen Bratz 2016 年 11 月 7 日
回答済み: KSSV 2016 年 11 月 8 日
Hello, I am having trouble implementing this code.
x = linspace(2,6); y = zeros(size(x)); z = zeros(size(x)); for ii = 1:length(x) if x(ii)<=5 y(ii) = (56-(8*(x(ii)-2)))/(2*x(ii)); z(ii) = int(y(ii),2,ii); else y(ii) = (56-25-(8*(x(ii)-2)))/(2*x(ii)); z(ii) = int(y(ii),2,ii); end end plot(x,y) hold on plot(x,z)
It works great until I try to add in the z part. What I need is a value of Z corresponding to each value of y I find in the loop. It's obvious that I am using the int function wrong but I don't know how.Any help would be great!
Thanks, Stephen
  1 件のコメント
Stephen Bratz
Stephen Bratz 2016 年 11 月 7 日
Here is the code file

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

回答 (1 件)

KSSV
KSSV 2016 年 11 月 8 日
To integrate you have to input a function with variables like x,y. In your case y(ii) is a number. There is no variable in it, it is a double class. How you want to integrate a number? I advice you to read the documentation part of int.

カテゴリ

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