How to create a function m-file to evaluate the function
where a is given and a=0.3
Thanks in advance
No products are associated with this question.
Direct link to this answer:
function f = my_func(x)
a = 0.3;
f = ((1+a) * sin(a*x) .* exp(-a*x)) ./ x;
Direct link to this comment:
error pops up saying ??? Undefined function or variable 'x'.
what do I do with an X then?
If you want to write as a function file, this is the way, and 'x' is an i/p argument, that you can read it from workspace, beore running the function file, like
>>x=3; % 'x' is variable
function f =my_func(x)
otherwise, you can do this using for looping operation.
If you try that and x contains any values that are not positive integers, then MATLAB will complain about you trying to index the array f. For example, if x was 1/2 then
f(x) = .....
f(1/2) = .....
and that is trying to assign a value to element # (1/2) in array f, which is not legal.
See my solution.
MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test
Opportunities for recent engineering grads.
New to MATLAB?
Choose your country to get translated content where available and see local events and offers. Based on your location, we recommend you select United States from the following list:
See all countries