how to use imported data in matlab equations?

조회 수: 1 (최근 30일)
Engineer Batoor khan mummand
Engineer Batoor khan mummand 2020년 10월 7일
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

채택된 답변

Walter Roberson
Walter Roberson 2020년 10월 7일
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
Walter Roberson
Walter Roberson 2020년 10월 8일
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
Engineer Batoor khan mummand 2020년 10월 8일
thanks you so much Dear Walter reberson:
i have no words about you , you have solved my problem.
once again thank you so much .

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by