Why does the variable 'ans' cannot be change when setting a domain? For example: I wanted to change the variable 'ans' to 'xofZ' but it keep saying it failed.

1 view (last 30 days)
ans=solve(Iy1,x);
ans(ans==real(ans));
ans(ans>=0 & ans<=5)
e.g.
xofZ=solve(Iy1,x);
xofZ(ans==real(xofZ));
xofZ(xofZ>=0 & xofZ<=5)

Accepted Answer

Voss
Voss on 18 May 2022
Edited: Voss on 18 May 2022
If you want to modify the value of xofZ, e.g., by having it retain only the real solutions, you must assign to xofZ.
When the variable was ans, you didn't have to assign to ans because ans always contains the last unassigned result.
syms x
xofZ = solve(x.^3 + 2.*x.^2 + 2.*x == 0,x)
xofZ = 
% notice it says, ans = 0
xofZ(xofZ==real(xofZ))
ans = 
0
% but xofZ is still what it was:
xofZ
xofZ = 
% compared to this, which modifies xofZ
xofZ = xofZ(xofZ==real(xofZ))
xofZ = 
0
xofZ = xofZ(xofZ>=0 & xofZ<=5)
xofZ = 
0

More Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!