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

2 views (last 30 days)
  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.

Answers (3)

madhan ravi
madhan ravi on 31 Jan 2019
Edited: madhan ravi on 31 Jan 2019

Ollie A
Ollie A on 31 Jan 2019
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 on 31 Jan 2022
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.

Categories

Find more on Symbolic Math Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!