How Do You Solve This MATLAB Array Calculation Error?

  • Thread starter Thread starter ja sam glup
  • Start date Start date
  • Tags Tags
    Matlab
Click For Summary
SUMMARY

The discussion centers on resolving a MATLAB array calculation error related to the equation y = (e^3x) / (sqrt(x+1)). The user initially attempted to define the function incorrectly, leading to errors. The correct approach involves using element-wise operations with the dot operator, specifically using the syntax y = (exp(3*x)) ./ (sqrt(x+1)), which allows MATLAB to compute values for an array of x from 1 to 10 without errors.

PREREQUISITES
  • Familiarity with MATLAB syntax and functions
  • Understanding of element-wise operations in MATLAB
  • Basic knowledge of exponential functions and square roots
  • Experience with defining symbolic variables in MATLAB
NEXT STEPS
  • Learn about MATLAB's element-wise operations and the significance of the dot operator
  • Explore MATLAB's array manipulation functions, such as arrayfun()
  • Study the use of symbolic variables in MATLAB for mathematical modeling
  • Investigate common MATLAB errors and debugging techniques
USEFUL FOR

Students learning MATLAB, educators teaching numerical methods, and anyone troubleshooting array calculations in MATLAB.

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.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 10 ·
Replies
10
Views
2K
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K