Why y6(x)=e^[(-ax)]^2 didin't work

1 view (last 30 days)
Artur Niewiadomski
Artur Niewiadomski on 11 Nov 2021
Edited: Jan on 11 Nov 2021
I want to calculate it, but it doesn't work :/
y6(x)=e^[(-ax)]^2

Answers (2)

Jan
Jan on 11 Nov 2021
Edited: Jan on 11 Nov 2021
Welcome to Matlab!
"It doesn't work" is not a useful description of the occuring problem. Post the error message instead or explain the difference between the result and you expectations.
I see 3 problems:
  • What is "e" in e^[(-ax)]^2?
  • "ax" is not the same as a * x.
  • y6(x) will not work in general, if x is not an integer > 0.
I guess:
y = exp(-a * x.^2)
These are programming fundamentals in Matlab. Please read the Getting Started chapters and look at Matlab's Onramp. This is more efficient to ask for the basics in the forum.

Walter Roberson
Walter Roberson on 11 Nov 2021
  1. MATLAB has absolutely no implied multiplication, not anywhere. If you want to multiply a and x then you need to put a multiplication operator between the two names. For this purpose, the multiplication operator to use use .* (period followed by asterisk), such as a.*x
  2. The equation asks you to take the square of x, not the square of (-ax) .
  3. For this purpose you will probably need to use the .^ operator instead of the ^ operator
  4. In MATLAB, [] is only used to build lists, such as [1, 1, 2, 3, 5, 8] . You should use () for prioritization.
  5. In MATLAB, is written as . You will find that to be quite common across different programming languages
  6. Having the (x) on the left side is not going to work if x is numeric, and you should instead be creating anonymous functions in such a case, such as y = @(x) sin(x.^2-1) . It is valid to have y(x) on the left hand side if x has been defined as a symbolic variable

Categories

Find more on Mathematics in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!