Integration containing multiple variable and plotting
이전 댓글 표시
Can anybody help me to integrate & plot in the following format, i.e. contains multiple variables?:
z = 0:0.1:10;
a = -0.5:0.1:1;
x = 0:0.1:2;
y = 2*exp(-0.5*z) + x;
I = 0.2 ∫(0.5*(a-y)+0.3) dx
integration limit : 0 to x
plot (I,x);
댓글 수: 10
Dyuman Joshi
2022년 4월 24일
편집: Dyuman Joshi
2022년 4월 24일
What's the value of a? Is there any relation between z & x ? If no, it's a straight forward integration, treating z variable as constant.
Also - integration limits are a number, not an array
I STAND CORRECTED. YOU CAN USE ARRAY INPUT AS INTEGRATION LIMITS AS STAR STRIDER MENTIONED
Supriya Khatoniar
2022년 4월 24일
Star Strider
2022년 4월 24일
@Dyuman Joshi — You are actually correct, the integration limits must be scalars.
The arrayfun function contains an implied loop, so each value of ‘x’ is presented to integral in turn as the upper limit of integration, creating the family of curves.
Torsten
2022년 4월 24일
I = 0.2 ∫(0.5*(a-y)+0.3) dx
together with
integration limit : 0 to x
makes no sense since the integration is with respect to x.
Dyuman Joshi
2022년 4월 24일
@Star Strider Thank you for the clarification, I learnt something new today!
@Torsten, since 'a' and 'y' or not dependent of 'x', you can treat them as constant in integration and proceed further.
@Supriya Khatoniar, Do check Star Strider's answer, and mentioned if it is helpful or not.
y depends on x.
And it doesn't matter: Integration variable and upper limit as identical variable makes no sense.
What should
integral_{0}^{x} a dx
be ?
It's always
integral_{0}^{x} a dx'
or something similar.
Star Strider
2022년 4월 24일
I agree, the ambiguities make this confusing. The original vectors are different lengths as well, so the original code as posted will obviously not work. I treated the ‘x’ in the integrand as separate from the vector ‘x’ and used the vector ‘x’ to define the upper limit of integration.
I have absolutely no idea what is actually intended here.
@Dyuman Joshi — My pleasure! Originally arrayfun was much slower than an equivalent loop, so I have not used it much. It is now much more efficient, and works here as a single-line substitute for a loop.
.
Dyuman Joshi
2022년 4월 24일
I agree, the question is not framed clearly.
@Torsten, I overlooked the edit. My bad. What you mentioned is correct.
@Star Strider, wow thanks. New info. I got to know that arrayfun is quite slow as you mentioned, on MATLAB Answers only, but didn't know it has now become more efficient.
Also, How do you check a function's efficiency? Just checking it's time to run a sample of code?
Star Strider
2022년 4월 24일
‘Also, How do you check a function's efficiency? Just checking it's time to run a sample of code?’
Supriya Khatoniar
2022년 4월 25일
채택된 답변
추가 답변 (1개)
Sulaymon Eshkabilov
2022년 4월 24일
0 개 추천
Use integral3: https://www.mathworks.com/help/matlab/ref/integral3.html
댓글 수: 1
Supriya Khatoniar
2022년 4월 24일
편집: Supriya Khatoniar
2022년 4월 24일
카테고리
도움말 센터 및 File Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
