Borrar filtros
Borrar filtros

Deriving symbolic equation based on the input string

5 visualizaciones (últimos 30 días)
Tommy
Tommy el 11 de Mayo de 2015
Hi everyone
I have a question regarding to the "input()" function. I know that I can input string with the function shown below, for example:
x = input('Please enter your input','s'
But what I want to do is to input a string and then do symbolic derivation based on the string that I input. For instance, the code below:
clear
clc
% Define the symbolic variable
syms x y a b m n p q H1 H2 H3 H4
% Define the equation
y = -(1/(2*x));
b = -(1/(3*a));
n = -(1/(4*m));
q = -(1/(5*p));
% Use the input function
R1 = input('Input the string 1: ','s');
R2 = input('Input the string 2: ','s');
R3 = input('Input the string 3: ','s');
R4 = input('Input the string 4: ','s');
% Derive the expression
K = simplify(expand(((R1*H1) + (R2*H2) + (R3*H3) + (R4*H4))/(R1 + R2 + R3 + R4)));
What I want to do is that user has to enter either y, b, n or q for each of the R1, R2, R3 and R4. Then R1 to R4 are then defined as a string, and they are called in the equation K. The equation K will be derived based on what the R1 to R4 are, which could be either y, b, n or q, since y, b, n and q were defined beforehand.
However, MATLAB gave me error. Could somebody help me please?
Thank you very much
Tommy

Respuestas (0)

Categorías

Más información sobre Symbolic Math Toolbox en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by