Plotting a piecewise function using either for or while loops
Afficher commentaires plus anciens
I want to make the following piecewise function:
f(x) = 5x for 0<x<3 = 2x^2 for 3<x<5 and = 32*ln(4/x)+16 for 5<x<7
and I need to make an M-script that evaluates for values of x starting at 0, and increasing in increments of 0.2 until x = 7, as well as showing a plot of the function against the x values.
Scripts so far:
for i = 3:0.2:5
y = 2*(i^3)
x = [3:0.2:5]
plot (x, y)
end
The first function calculates fine for 0<x<3, but I’m wondering why this code doesn’t graph the first part of the function, and how I could get it to graph. Also, how do I implement the other functions in as well? Do I connect more loops?
Thanks for your assistance. I'm relatively new to MATlab, so I don't understand advanced codes - so if possible please keep it simple. =)
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Networks dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!