How can I properly enter this function in MATLAB
Mostrar comentarios más antiguos
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.
Respuestas (2)
Walter Roberson
el 2 de Oct. de 2022
My guess is
P = p(a+b).*(3-sqrt(3*a+b).*(a+3*b)) ./ (a+b)
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.
Categorías
Más información sobre Operators and Elementary Operations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!