Clear Filters
Clear Filters

how to accept equations from the user and convert to a matrix?

2 views (last 30 days)
Please help me. I am writing a code to accept equations from the user and then convert it to a matrix to perform row operations. The purpose is to create a generic code for a system of linear equations. Following is the code .
m = input ('Enter number of unknowns: ');
n = input ('Enter number of equations: ');
syms x y
for j=1:n
equ(j)= input ('Enter equations: ','s');
end
for j=1:n
func(j) = evalin(symengine, equ(j));
end
for j=1:n
[A,B] = equationsToMatrix([func(j)], [x, y])
end

Accepted Answer

Walter Roberson
Walter Roberson on 15 Sep 2017
Change
equ(j)= input ('Enter equations: ','s');
to
equ(j) = string( input ('Enter equations: ','s') );
This requires R2016b or later.
This change is adjusting for the fact that in MATLAB, input() with the 's' parameter requires a character vector, which will be a vector, and vectors cannot be stored into a single location like equ(j) . The string() call converts the character vector into a string object, and string objects can be stored into a single location like equ(j)

More Answers (0)

Categories

Find more on Characters and Strings in Help Center and File Exchange

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!