How can I properly enter this function in MATLAB
1 view (last 30 days)
Show older comments
I keep trying to enter an equation in my MATLAB code, and i keep getting array indec errors or mismatched delimeters errors and I was wondering if someone could tell me how I could enter this function: P=p(a+b)(3-sqrt(3*a+b)(a+3*b))/a+b)) in MATLAB.
0 Comments
Answers (2)
DGM
on 2 Oct 2022
Moved: DGM
on 2 Oct 2022
Three things:
- The expression does have imbalanced parentheses
- MATLAB doesn't support implicit multiplication of terms
- I don't know the size of these variables
As a consequence of 2 and 3, I don't know whether the expression is supposed to be
P = p(a + b) ... % p is an array and a+b is the index into the array
or
P = p.*(a + b) ... % p is an array (or a scalar) being multiplied by the sum of a and b
Similarly, I can't really know what the intended parentheses is.
You can start by sorting out where the extra parentheses needs to be added/removed. Assuming the remaining operations are elementwise, you need to explicitly multiply the terms. Depending on what's intended, you might wind up with something like this.
P = p.*(a + b).*(3 - sqrt(3*a + b).*(a + 3*b))./a + b;
Bear in mind that's just a guess.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!