Why the plot figure is empty

2 ビュー (過去 30 日間)
Zhiying Wang
Zhiying Wang 2019 年 11 月 1 日
回答済み: Walter Roberson 2019 年 11 月 2 日
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 件のコメント
Walter Roberson
Walter Roberson 2019 年 11 月 1 日
You cannot do that.
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 Center および File ExchangeConversion Between Symbolic and Numeric についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by