How would I plot the function p(x)=e^(-0.5x)*(4-x)-2 in the range of -2 to 10 as well as its derivative?
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Jennifer
am 9 Feb. 2023
Bearbeitet: Les Beckham
am 9 Feb. 2023
How would I plot the function p(x)=e^(-0.5x)*(4-x)-2 in the range of -2 to 10 as well as its derivative? When I run it I get an invalid operator so I assumed I had to use . after the variables but that gives me the error: Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters. Can someone please help me out.
x = -2:0.1:10;
p = (exp(-0.5*x.)*(4-x.))-2;
pp = 0.5*exp(-0.5*x.)*x.-3*exp(-0.5*x.);
plot(x,p)
0 Kommentare
Akzeptierte Antwort
Les Beckham
am 9 Feb. 2023
Bearbeitet: Les Beckham
am 9 Feb. 2023
You had the '.' characters in the wrong place; they go right before the '*' to get element-by-element multiplies.
x = -2:0.1:10;
p = (exp(-0.5*x) .* (4-x)) - 2;
pp = 0.5*exp(-0.5*x) .* x - 3*exp(-0.5*x);
plot(x, p, x, pp)
grid on
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!