Azzera filtri
Azzera filtri

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

2 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Walter Roberson
Walter Roberson il 15 Set 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)

Più risposte (0)

Categorie

Scopri di più su Characters and Strings in Help Center e File Exchange

Tag

Non è stata ancora inserito alcun tag.

Community Treasure Hunt

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

Start Hunting!

Translated by