How do I plot this non-linear function...
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
This question is pretty elementary, but I'm new to MATLAB and am having trouble with this. I want two curves, one of r vs. T (which is easy, it's just a fourth power function) and one of r2 vs. T (on the same graph). That's fine, except r2 is r multiplied by some function of T (which will be on the x-axis) that I called k.
T=180:1:360
k=.8823-((T-179)*(.0039))
s=1.1e-2
r=s*(T.^4)
r2=k*s*(T.^4)
plot(T,r,'-k',T,r2)
This doesn't work...This is just an example, but my head still isn't around the matrix interpretation of plotting, so any tips for plotting stuff like this or non-linear functions in general would be appreciated
0 comentarios
Respuestas (2)
Matt Fig
el 20 de Feb. de 2011
One minor change will make it work.
T = 180:1:360;
k = .8823-((T-179)*(.0039));
s = 1.1e-2;
r = s*(T.^4);
r2 = k.*s.*(T.^4); % Or r2 = k.*(s*(T.^4)); Or r2=(k*s).*(T.^4);
plot(T,r,'-k',T,r2)
In general, whenever you have two or more vectors and you want their product to be a vector, use element-by-element multiplication (include the dot). Look at a small example:
a = 1:3
b = 5:7
a.*b
The same goes for division and exponentiation.
0 comentarios
Matt Tearle
el 20 de Feb. de 2011
You should be getting an error on the line that defines r2 (before you even get to the plot). As Matt Fig points out, the multiplication there should be .* (element-wise), not *.
0 comentarios
Ver también
Categorías
Más información sobre Discrete Data Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!