Why the plot figure is empty

3 次查看(过去 30 天)
Zhiying Wang
Zhiying Wang 2019-11-1
y = ones(1,11,'sym');
syms a;
n=0;
for x = -a/2:a/10:a/2;
n=n+1;
y(n)=(15/8*a)^(1/2)*(1-4*x^2/a^2);
end
fplot(-a/2:a/10:a/2,y)
I want to plot y=(15/8*a)^(1/2)*(1-4*x^2/a^2), x is from -a/2 to a/2.
Why the figure is empty? There is Warning: Error updating ParameterizedFunctionLine. The following error was reported evaluating the function in FunctionLine update: Non-scalar in Uniform output, at index 1, output 1.
Set 'UniformOutput' to false.
  4 个评论
Steven Lord
Steven Lord 2019-11-1
I want the final plot contains a, instead of setting a value for a
You can't. Let's say a was 1. What does your y function look like?
>> syms a x
>> y = (15/8*a)^(1/2)*(1-4*x^2/a^2);
>> vpa(subs(y, a, 1))
ans =
1.369306393762915283642424457002 - 5.477225575051661134569697828008*x^2
What if a was -1 instead?
>> vpa(subs(y, a, -1))
ans =
- x^2*5.477225575051661134569697828008i + 1.369306393762915283642424457002i
In general you can't even say whether or not y is a real-valued or complex-valued function! How would you expect MATLAB to plot the function under those circumstances?

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2019-11-2
How about this:
for a = linspace(0,5,20)
x = -a/2:a/10:a/2;
y = -((4*x.^2)/a^2 - 1)*((15*a)/8).^(1/2);
plot3(x,y,repmat(a,1,length(x)),'displayname', num2str(a));
hold on;
end;
hold off
view(3)
legend show

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by