Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

Error wiritting an expression

1 Ansicht (letzte 30 Tage)
Hicham Lhachimi
Hicham Lhachimi am 28 Dez. 2016
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
Hi,
I have an error expression when I write the expression below:
Z=(0.5176*(116*((1./(X+0.08*Y))-(0.035./(Y.^3+1)))-0.4*Y-5)*exp((-21)*((1./(X+0.08*Y))-(0.035./(Y.^3+1))))+0.0068*X)
So to look for the error, I write the first expression which is :
A=0.5176*(116*((1./(X+0.08*Y))-(0.035./(Y.^3+1)))-0.4*Y-5)
and I simulate it and it works
the same thing for the second expression, when I simulate it it works :
B=(exp((-21)*((1./(X+0.08*Y))-(0.035./(Y.^3+1)))))+0.0068*X
The problem is that the expression Z is equal to A*B and when I simulate it, it generates an error expression
  2 Kommentare
KSSV
KSSV am 28 Dez. 2016
Post the full code....you have to read about element by element matrix operations.
Hicham Lhachimi
Hicham Lhachimi am 28 Dez. 2016
Bearbeitet: Walter Roberson am 28 Dez. 2016
In the code try to simulate the two expression that are commented to see that they are working.
Here is the code :
x=0:1:20
y=0:2:20
[X, Y]=meshgrid(x,y)
_% Z=0.5176*(116*((1./(X+0.08*Y))-(0.035./(Y.^3+1)))-0.4*Y-5)_
_% Z=(exp((-21)*((1./(X+0.08*Y))-(0.035./(Y.^3+1)))))+0.0068*X_
Z=0.5176*(116*((1./(X+0.08*Y))-(0.035./(Y.^3+1)))-0.4*Y-5)*(exp((-21)*((1./(X+0.08*Y))-(0.035./(Y.^3+1)))))+0.0068*X
mesh(X,Y,Z)

Antworten (1)

Star Strider
Star Strider am 28 Dez. 2016
Bearbeitet: Star Strider am 28 Dez. 2016
You have used element-wise calculations in your code except for the multiplication between the terms:
Z = A .* B
If ‘A’ and ‘B’ work independently, then that should make them work in ‘Z’ as well.
----------------------------
EDIT
x=0:1:20;
y=0:2:20;
[X, Y]=meshgrid(x,y);
Z=0.5176*(116*((1./(X+0.08*Y))-(0.035./(Y.^3+1)))-0.4*Y-5).*(exp((-21)*((1./(X+0.08*Y))-(0.035./(Y.^3+1)))))+0.0068*X;
→ ↑ DO ELEMENT-WISE MULTIPLICATION HERE
figure(1)
mesh(X,Y,Z)
grid on

Community Treasure Hunt

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

Start Hunting!

Translated by