MATLAB doesn't plot my function
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Pedro Almeida
am 6 Dez. 2022
Kommentiert: Askic V
am 6 Dez. 2022
This is probably a dumb question but when I try to plot this function nothing appears:
format long
y = @(x) - sin(x);
z = @(x) x.^2;
test1 = @(x) y(x)-z(x);
x = fzero(test1,[0 1])
plot(test1)
It also gives my the following error:
error: unary operator '.'' not implemented for 'function handle' operands
error: called from
__plt__>__plt1__ at line 189 column 8
__plt__ at line 118 column 18
plot at line 229 column 10
ex1 at line 6 column 1
0 Kommentare
Akzeptierte Antwort
Alan Stevens
am 6 Dez. 2022
Try
fplot(test1)
4 Kommentare
Askic V
am 6 Dez. 2022
It evaluates the function test1. Please have a look at the documentation:
https://www.mathworks.com/help/matlab/ref/feval.html
Weitere Antworten (1)
Sam Chak
am 6 Dez. 2022
You probably want to plot like this?
y = @(x) - sin(x);
z = @(x) x.^2;
fun = @(x) y(x) - z(x);
fplot(y, [-pi pi]), hold on
fplot(z, [-pi pi]),
xsol1 = fzero(fun, -1)
xsol2 = fzero(fun, 1)
plot(xsol1, y(xsol1), 'o')
plot(xsol2, y(xsol2), 'p'), hold off
xlabel('x'), grid on,
legend('sin(x)', 'x^2')
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements 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!