How do I define a function that evaluates in input

A
aldburg · Jan 15, 2024 · 1.9K views
Question
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 PhD Expert
Answered Aug 29, 2026
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.

100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!