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
类别
在 帮助中心 和 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!
