Problem with for loop plotting a graph

18 次查看(过去 30 天)
Hi I'm really new to Matlab so you'll have to bare with me. I'm trying to plot a graph using the for function but to no avail.
I'm using the following code:
>> for a=2.0:-0.02:0.0
p=[f(a),g(a),h(a),r(a),t(a)] (where f,g,h,r,t are complicated functions of a I don't fancy writing down.)
R=roots(p)
C=imag(R)
c=C(1,1)
....
end
I'm looking to plot the complex part of the first root of each polynomial against each value of a or if its possible plotting the complex part of every root against a for every a on the same graph with different colours representing each root.
Thanks, sorry if the problem is ill described.
  2 个评论
madhan ravi
madhan ravi 2018-12-6
编辑:madhan ravi 2018-12-6
attach the script file and the relevent function files

请先登录,再进行评论。

采纳的回答

Star Strider
Star Strider 2018-12-6
The Symbolic Math Toolbox is inefficient for this sort of problem.
Try this:
U = 1;
B = 0.1;
H = 0.5;
pfcn = @(a) [2*exp(2*a*(1-H)).*(1 - tanh(a*H)), -6*U*(1 + tanh(a*H)).*exp(2*a*(1 - H)) + 2*U*(1 - tanh(a*H)),(7*U^2 *(1 + tanh(a*H)) - 2*B^2 *tanh(a*H)).*exp(2*a*(1 - H)) - 5*U^2 *(1 - tanh(a*H)), exp(2*a*(1 - H)).*(2*U*B^2 *tanh(a*H) - 4*U^3 *(1 + tanh(a*H))) - (2*U*B^2 *tanh(a*H) - 4*U^3 *(1 + tanh(a*H))), U^2 *(U^2 *(1 + tanh(a*H)) - B^2 *tanh(a*H)).*exp(2*a*(1 - H)) - U^2 *(U^2 *(1 - tanh(a*H)) - B^2 *tanh(a*H))];
a=2.0:-0.02:0.0;
for k1 = 1:numel(a)
p = pfcn(a);
R = roots(p);
C(:,k1) = imag(R);
end
figure
plot(a, C, '.')
grid
figure
meshc(C)
grid on
That should tell you all you need to know about the imaginary roots of your function at each ‘a’ value.
  14 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Linear Algebra 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by