MATLAB: How to write down functions matlab function How do i write xe^x^2-10^6 and 2x^2 e^x^2+e^x^2 on matlab? I can't figure it out. Matlab says it's an invalid expression Best Answer You need to specify the multiplication operator in MATLAB explicitly. Also, 'e' is not defined as a constant in MATLABy1 = x*exp(x^2)-10^6y2 = 2*x^2*exp(x^2)+exp(x^2)If 'x' is a vector then use element-wise operatorsy1 = x.*exp(x.^2)-10^6y2 = 2*x.^2.*exp(x.^2)+exp(x.^2)Completing this free course: https://www.mathworks.com/learn/tutorials/matlab-onramp.html will help understand the basics of MATLAB. Related SolutionsMATLAB: Derivative of a Function If you have the Symbolic Toolbox:>> g = @(x) exp(x^2-2)g = @(x)exp(x^2-2)>> syms x>> diff(g(x))ans =2*x*exp(x^2 - 2) MATLAB: Writing several sums of terms in matlab I would write it as one anonymous function:F = @(x) sum(sum([x exp(-x)]' * [6:6:300],1),2);Y = F(1)Y = 10.4643e+003 Related QuestionColor area between functionsIncorrect Matlab formError occur with comment “Subscript indices must either be real positive integers or logicals” while plotting
Best Answer