How Do You Solve This MATLAB Array Calculation Error?

  • Thread starter Thread starter ja sam glup
  • Start date Start date
  • Tags Tags
    Matlab
AI Thread Summary
The discussion revolves around solving a MATLAB error related to calculating values of y for the equation y = (e^3x) / (sqrt(x+1)) using an array of single-digit values for x. The user initially attempted to define the function incorrectly, leading to an error message. A solution was provided, highlighting the correct syntax for element-wise operations in MATLAB, specifically using the dot operator for division. This adjustment allows for the proper calculation of y values across the defined array of x. Understanding the importance of element-wise operations in MATLAB is crucial for resolving similar issues.
ja sam glup
Messages
7
Reaction score
0

Homework Statement


Use an array for single digit values of x [1,10] to find values of y for the equation y = (e^3x) / (sqrt (x+1)).

Homework Equations


The Attempt at a Solution


So, I tried defining the function as Function [ (e^3x) / (sqrt (x+1))] = y(x) , but that gave me an error message. I then tried to just define x and y first with syms x; and syms y;, and then define y as y = (e^3x) / (sqrt (x+1)).

However, since this is actually not a function, i was not able to arrayfun() to get the answer that I needed. This is my first MATLAB homework and the TA didn't explain anything, he just said to do it.

Any help would be greatly appreciated.
 
Physics news on Phys.org
Here this will fix your problem

Code:
x = 1:10;
y= (exp(3*x)) ./ (sqrt (x+1))

Take note of the dot (" . ") That tells MATLAB to perform a value by value operation rather than a matrix operation.
 
Back
Top