how can i solve such two problems in single script file and run them?

2 次查看(过去 30 天)
  1. Write a user-defined function for the following math function:
y(x)=(-0.3x^4+6x^2 ) e^(-0.2x)
The input for the function is x and the output for the function is y.
  1. Write a user-defined function for the following math function:
r(θ)=5 cos⁡(2 sin⁡(θ) )
The input to the function is θ in radians and the output is r.

回答(3 个)

madhan ravi
madhan ravi 2019-1-31
编辑:madhan ravi 2019-1-31

Ollie A
Ollie A 2019-1-31
There are two ways you could construct your function, as a symbolic function using syms, or as an expression that operates on a predefined input. Using the symbolic function method, your first function is constructed as so:
syms y(x)
y(x) = (-0.3*x^4 + 6*x^2)*exp(-0.2*x); % Your function
double(f(userinput))
Or the simpler method:
x = linspace(0,100,1000); % Inputs
y = (-0.3*x.^4 + 6*x.^2).*exp(-0.2*x); % Your function
Now that you've seen these two examples you should be able to construct your second function.
Note: using syms may require the symbolic functions toolbox.

Angela Borer
Angela Borer 2022-1-31
You can include the code in a loop. For example, you could create a variable. Then, you would use a loop to run through each of your two problems. Inside for loop, you should visit https://www.aussiessay.com/ for further info and call the script with the appropriate parameters. If you want, you can also add an else statement that runs if the problem has not been solved by any of the scripts inside of the loop.

类别

Help CenterFile Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by