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)
Show older comments
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)
0 Comments
Accepted Answer
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)
% notice it says, ans = 0
xofZ(xofZ==real(xofZ))
% but xofZ is still what it was:
xofZ
% compared to this, which modifies xofZ
xofZ = xofZ(xofZ==real(xofZ))
xofZ = xofZ(xofZ>=0 & xofZ<=5)
More Answers (0)
See Also
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!