Clear Filters
Clear Filters

how to use imported data in matlab equations?

2 views (last 30 days)
Hi to everyone:
i have four equations and four unknowns which is given below:
s*x+4y-3z+12m=100
2x+3*s*y+4z+200m=200
3x+y+z+4*s*m=150
25x+20y+10*s*m=250
where x,y,m znd z is unknown and s is given in excel sheet .
i want to find above unknowns by using s data which is given in excel sheet and than plot(x,s):
i have written code in matlab but it gave me error:
clc;
close all;
clear all;
syms x y m z
myData = readtable('batorrrkhaan.xlsx','Sheet','Taxila-hour')
s = myData.solar_radiation
iThreshold = 200
iKeep = s >= iThreshold
s = s(iKeep)
eqn1=s.*x+4*y-3*z+12*m==100;
eqn2=2*x+3*s.*y+4*z+200*m==200;
eqn3=3*x+y+z+4*s.*m==150;
eqn4=25*x+20*y+10*s.*m==250;
[x,y,t,z]=vpasolve([eqn1, eqn2, eqn3,eqn4],[x,y,t,z]);
x
y
t
z
error is :
z =
Empty sym: 0-by-1
x=
Empty sym: 0-by-1
m=
Empty sym: 0-by-1
y=
Empty sym: 0-by-1

Accepted Answer

Walter Roberson
Walter Roberson on 7 Oct 2020
eqn1=s.*x+4*y-3*z+12*m==100;
That does not define one equation: it defines one equation for each value of s.
[x,y,t,z]=vpasolve([eqn1, eqn2, eqn3,eqn4],[x,y,t,z]);
That is length(s) times 4 equations being solved for 4 variables. There are no scalar values of x, y, t, z that are able to satisfy all of the equations simultaneously.
solve() does not know that you mean that you want to solve for x, y, z, t per s value. Using one row of equations per s value will not help: solve() treats the set of equations as if you had done reshape(equations, [], 1)
You need to separate the equations yourself.
[x, y, t, z] = arrayfun(@(E1, E2, E3, E4) vpasolve([E1, E2, E3, E4], [x, y, t, z]), eqn1, eqn2, eqn3, eqn4)
  13 Comments
Walter Roberson
Walter Roberson on 8 Oct 2020
Either you have a broken MATLAB installation or else you forgot to tell us that you using an old release of MATLAB.
Remove the 'PreserveVariableNames', true option from the call. You may need to adjust the name in the 'varname' assignment, such as to 'DiffuseHorizontalRadiation_Wh_m_2_'
Engineer Batoor khan mummand
thanks you so much Dear Walter reberson:
i have no words about you , you have solved my problem.
once again thank you so much .

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!