evaluate expression
3 次查看(过去 30 天)
显示 更早的评论
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 ?
0 个评论
采纳的回答
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
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.
更多回答(1 个)
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))
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Function Creation 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!