How do I define a function that evaluates in input

Illustration
aldburg - 2024-01-15T12:04:54+00:00
Question: How do I define a function that evaluates in input

Currently been typing:     theta_Degree=40 theta=(theta_Degree*pi/180) T = [cos(theta)^2 sin(theta)^2 2*cos(theta)*sin(theta); sin(theta)^2 cos(theta)^2 -2*cos(theta)*sin(theta); -cos(theta)*sin(theta) cos(theta)*sin(theta) cos(theta)^2-sin(theta)^2] But I'd like to simply type T(theta) from saved script but I can't seem to figure out how to.

Expert Answer

Profile picture of Prashant Kumar Prashant Kumar answered . 2025-11-20

function y=T(theta_Degree)
theta=theta_Degree*pi/180;
y=[cos(theta)^2 sin(theta)^2 2*cos(theta)*sin(theta);sin(theta)^2 cos(theta)^2 -2*cos(theta)*sin(theta);-cos(theta)*sin(theta) cos(theta)*sin(theta) cos(theta)^2-sin(theta)^2];
end

Then type in command line

T(40)

and see the results.


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!