필터 지우기
필터 지우기

Plot returns one point

조회 수: 1 (최근 30일)
buszcini
buszcini 2017년 12월 4일
편집: buszcini 2017년 12월 4일
Hello everybody, I'm having problem with plotting, here's my piece of code
a=0;
b=5;
n=100;
s=zeros(1,n);
z=0;
h=(abs(b-a))/n;
x=a:h:b;
y=(x.^0.5)+sin(x)+5;
for i=1:n
t=(y(i)+y(i+1))/2;
s=s+(y(i)+y(i+1)+4*t)*h/6;
end
plot(n,s)
plot returns only one point, I can't really think of way to make 's' variable saved as vector so it could plot properly, i'd appreciate any help
  댓글 수: 1
Adam
Adam 2017년 12월 4일
What are you trying to do? There doesn't seem any point to having the s on the right side of the assignment.
Storing in an array would normally just be a case of adding the obvious array index:
s(n)=s(n)+(y(i)+y(i+1)+4*t)*h/6;
but in your case it isn't obvious what value of 's' you are trying to add. Are you attempting to accumulate values?

댓글을 달려면 로그인하십시오.

답변 (1개)

buszcini
buszcini 2017년 12월 4일
편집: buszcini 2017년 12월 4일
I'm trying to use simpsons rule to approximate integration, this is why s is on the right side of the equation. I want the program to increase accuracy each iteration, and then make a plot including approximated value dependent on number of iterations. I'm new to this, still getting white plot even tho variable 's' is 1x100 double

카테고리

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