evaluate expression

조회 수: 8 (최근 30일)
omnia
omnia 2011년 5월 12일
I have equation y=x*exp( (1-y)/(A*y)*B ) where A nd B constants in my program. I have a vector values for x. How can I evaluate y to plot y versus x ?

채택된 답변

Andrei Bobrov
Andrei Bobrov 2011년 5월 12일
ezplot(['y-x*exp( (1-y)/(' num2str(A) '*y)*' num2str(B) ')'],[x(1) x(end)])
more
As = ...;
Bs = ...;
y = zeros(size(x));
for j = 1:length(x)
y(j) = fzero(@(y)y-x(j).*exp( (1-y)./(As*y)*Bs ),1);
end
plot(x,y);
  댓글 수: 2
John D'Errico
John D'Errico 2011년 5월 12일
It is generally not a good idea to convert the numeric values into strings to then pass into ezplot. This loses precision. Far, far better is to use an anonymous function here.
omnia
omnia 2011년 5월 13일
Thank you alot

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Andrew Newell
Andrew Newell 2011년 5월 12일
It would be simpler to provide y and solve for x:
y = -1:0.01:1;
x = y.*exp(- (1-y)./(A*y)*B );
In plotting this, you have to be careful because x goes to Inf or -Inf as y approaches zero from below:
I = y < 0 & abs(x) < 10;
plot(x(I),y(I))
hold on
I = y > 0 & abs(x) < 10;
plot(x(I),y(I))
  댓글 수: 1
omnia
omnia 2011년 5월 13일
yes I know it is easier to provide y and solve for x, but I don't have y. The input to my file is x values.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by