How to plot a function against a matrix?

I am having trouble plotting the function g(x)=a+(b*x)+(c*x^2) against the matrix r2=(0:.1:10) but I am struggling to find a way to do this. What should I write in my script to allow me to make a scatter plot of this function?

답변 (1개)

Robert
Robert 2015년 10월 21일
편집: Robert 2015년 10월 21일

0 개 추천

I am assuming you mean to find the values of your function g(x) over all values defined in r2. If a, b, and c are scalars, then the only change you need is to use the element-wise power operator: .^
r2 = 0:0.1:10;
g = a + b*r2 + c*r2.^2;
Then you can plot g against r2 to view the results. For example:
plot(r2,g)
plot(r2,g,'o')
scatter(r2,g)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

질문:

2015년 10월 21일

편집:

2015년 10월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by