I have the function y = (x+2)^2/(3x+1) over the range 1=<x=<2 and when I graph it the plot stops at 1 on the x axis so when I put in the range into the data bounds it doesn't show up. I'm not sure if I'm typing the function out wrong or what I'm doing.
here is what I have:
clc;
x = linspace(0,1,100);
y = (x+2)^2./(3*x+1);
plot(x,y);
I've tried different values for the linspace, putting a "." before the ^2
Any help would be appreciated

 Akzeptierte Antwort

KSSV
KSSV am 13 Sep. 2017

0 Stimmen

x = linspace(0,1,100);
y = (x+2).^2./(3*x+1);
plot(x,y);
REad about element by element operation...use .^ instead of ^.

3 Kommentare

Ryan Elway
Ryan Elway am 13 Sep. 2017
Bearbeitet: Ryan Elway am 13 Sep. 2017
Thank you but I have tried that. But for some reason the plot on the x axis is still stopping at 1. I will try to mess around with it a little more.
KSSV
KSSV am 13 Sep. 2017
The plot is stopping on xaxes at 1, because you have provided x values till 1 only.
See this:
x = linspace(0,100,1000); % change limits here
y = (x+2).^2./(3*x+1);
plot(x,y);
Ryan Elway
Ryan Elway am 13 Sep. 2017
Thank you again I actually figured it out I changed the linspace part to
x = linspace(0,2,100);
thanks again, my mistake

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Aryan Safaie
Aryan Safaie am 13 Sep. 2017

0 Stimmen

Dear Ryan,
Are you sure that adding a '.' before the '^2' doesn't help? When I try the following line when calculating y, I get a plot that looks correct:
y = (x+2).^2./(3*x+1);
Best,
-aryan

1 Kommentar

Ryan Elway
Ryan Elway am 13 Sep. 2017
I had x = linspace(0,1,100) instead of linspace(0,2,100) thank you for the help though!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Hilfe-Center und File Exchange

Tags

Gefragt:

am 13 Sep. 2017

Kommentiert:

am 13 Sep. 2017

Community Treasure Hunt

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

Start Hunting!

Translated by