How to use a vector to make a graph?

8 ビュー (過去 30 日間)
Cassandra Haynes
Cassandra Haynes 2019 年 3 月 22 日
回答済み: Kevin Phung 2019 年 3 月 23 日
I want to use a vector to make a scatter plot. Ie, y(i)=v(i,1) from my vector. I managed to get from the vector to something resembling the results using a for loop, but I am unable to plot it from there. Here is the code I am using. The part I need help starts at the asterisks in the code. Thanks for the help!
a=1;
b=3;
c=-0.1;
d=0.2;
e=0.3;
n=10;
f=(b-a)/n;
A = toeplitz([2,-1,zeros(1,n-2)]);
A(1,1)=1;
A=(1/f)*A
u=zeros(n,1);
u(1,1)=e*f*(a/2+.2/6)-c;
for i=2:(n-1)
u(i,1)=e*f*(a+.2*((i)-1));
end
u(n,1)=e*f*(a+.2*(n-1))+d/.2;
v=A\u;
x=1:1:100;
y=-.3*(x.^3-27)/6+(.2+.3/2)*(x-3)+.2;
intervals = 1:1:n;
plot(x,y);
*****************************************************
for i=1:n
res(i)=v(i,1);
end
input=1:1:n;
plot(input,res(input));

回答 (1 件)

Kevin Phung
Kevin Phung 2019 年 3 月 23 日

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by