How do i use an unknown from an unsolved identity in my equations?

Hello, I'm a newbie to MATLAB and am having a problem with something which I believe should be quite simple.
I have a comlicated identity, the unknown of which I need in another equation. The code below shows a simplified version of what I'm trying to do.
clear all
clc
syms m
solve('m+6=4-m', m)
x=[0:1:10];
for i=1:11
y(i)=m*x(i)+5;
end
hold on
plot (x, y)
It's easy to see here that m = -1, and if I replace lines 3 and 4 with "m=-1;", I get my graph. However my identity is much more complicated than that shown and I can't rearrange it as "m=...". Can anyone help? I hope this was clear, please let me know if more information is needed.
These are the error messages I'm getting:
Error using sym/solve>getEqns (line 418)
List of equations must not be empty.
Error in sym/solve (line 226)
[eqns,vars,options] = getEqns(varargin{:});
Error in Test (line 4)
solve('m+6=4-m', m)

 Accepted Answer

There are some syntax issues in your code. Check the following code
clear all
clc
syms m
m_ = solve(m+6==4-m, m);
x= 0:1:10;
y = zeros(size(x)); % pre-allocation
for i=1:11
y(i)=m_*x(i)+5;
end
hold on
plot (x, y)

4 Comments

Thanks very much Ameer, I appreciated the quick responce.
Your code works great!
I still have some problems, which I've narrowed down to difficulties using trig functions in the identities. I'm guessing this is because trig gives rise to multiple solutions. For example, these codes result in no graph/error. I'm not sure if you or anyone here can help or if I should phrase it as a new question in the forum.
clear all
clc
syms m
m_ = solve(sind(m)==0.5, m);
x= 0:1:10;
y = zeros(size(x)); % pre-allocation
for i=1:11
y(i)=m_*x(i)+5;
end
hold on
plot (x, y)
and
clear all
clc
syms m
m_ = solve(sind(m)+cosd(m)==1.4, m);
x= 0:1:10;
y = zeros(size(x)); % pre-allocation
for i=1:11
y(i)=m_*x(i)+5;
end
hold on
plot (x, y)
Yes, this happens because you have two solutions. Following shows how to correctly solve it
clc
syms m
m_ = solve(sind(m)==0.5, m);
x= 0:1:10;
y = zeros(numel(x), numel(m_)); % pre-allocation
for i=1:11
y(i, :)=m_*x(i)+5;
end
hold on
plot (x, y)
and
clc
syms m
m_ = solve(sind(m)+cosd(m)==1.4, m);
x = 0:1:10;
y = zeros(numel(x), numel(m_)); % pre-allocation
for i=1:11
y(i, :)=m_*x(i)+5;
end
hold on
plot (x, y)
Legend, thanks Ameer. Disertation back on track!

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2020a

Tags

Community Treasure Hunt

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

Start Hunting!