I don't know why you're saying it's an invalid expression. Help me
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
kubel
el 12 de Sept. de 2023
Editada: John D'Errico
el 12 de Sept. de 2023
clear all; close all;
x=linspace(-2*pi,2*pi,100);
y1=sin(x^2);
y2=cos^2(x);
figure(1)
plot(x,y1,x,y2)
grid on
title('HW#1 test -2_pi and 2_pi')
xlabel('-2pi < x < 2pi')
ylabel('sin(x^2) and cos(x)^2')
legend('y = sin(x)','y = cos(x)')
0 comentarios
Respuesta aceptada
Más respuestas (1)
John D'Errico
el 12 de Sept. de 2023
Editada: John D'Errico
el 12 de Sept. de 2023
You NEED to learn about the dotted operators, thus .*, ./, and .^ operators.
When x is a vector, for example, this:
x = 1:5
So we see it is a row vector. MATLAB has special uses for ^, * and / that apply to linear algebra, vectors and matrices. So if you want only to square the elements of x,
x.^2
The dotted operator tells MATLAB to square EACH element of the result. Similarly, we could do this
x.*x
Again, multiply each pair of elements in turn.
But when you did this:
x^2
It generates an error.
I would strongly suggest the MATLAB Onramp tutorials.
Ver también
Categorías
Más información sobre Get Started with MATLAB en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!