Maximum value of the function

2 次查看(过去 30 天)
Samir
Samir 2011-11-8
P=1.008*V-(10^-10)*V*exp(V/0.026);
I want to find the maximum value of P for some value of V. What is an easy way.
And I am trying to plot V vs P with the following code but not able to:
subs V;
V=0:0.001:0.6;
P(V)=1.008*V-(10^-10)*V*exp(V/0.026);
plot(V,P);

回答(1 个)

David Young
David Young 2011-11-8
There are three problems with your code. First, this is a normal numerical computation, so you don't need subs V at the start.
Second, to multiply two vectors element by element you need to use the .* operator (* is matrix multiplication). In fact, it's clearest to use .* for all the multiplications here, as none is a matrix multiplication.
Third, P(V) on the left means "assign the result to those elements of P indexed by V". (Remember, this is code, not a mathematical formula.) V doesn't make sense as an index vector, but all you need to do is assign the result vector to P as a whole. Thus the corrected code is
P=1.008.*V-(10^-10).*V.*exp(V./0.026);
or, with clearer layout and the constant expressed conventionally,
P = 1.008 .* V - 1e-10 .* V .* exp(V ./ 0.026);
On your first question, to find the maximum you can differentiate the formula analytically, set the result to zero, solve for the value of V, and substitute to get the value of P.

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by