Effacer les filtres
Effacer les filtres

How to solve a linear equation with a variable inside the matrix,

2 vues (au cours des 30 derniers jours)
Salar
Salar le 31 Jan 2013
I am trying to solve a linear equation with 3 unknowns that is in the form of A*X=B , and one element in B varies with a variable which I call it to be d=[0:50] , and at the end I need to graph these 3 unknowns as a function of d , but I keep getting errors for dimension , I think the problem is that I have a matrix inside another, I tried to run a loop, but I still get the same error , I have my code down here, so please advice me, I really appreciate it.
clear all
close all
clc
d=[0:50];
A=[1 1 1;10 28 40;144 -240 180];
B=[-40000;-40000*d;0];
F=linsolve(A,B);
plot(d,F)

Réponse acceptée

Shashank Prasanna
Shashank Prasanna le 31 Jan 2013
clear all
close all
clc
d=[0:50];
A=[1 1 1;10 28 40;144 -240 180];
B=[-40000;-40000;0];
F = zeros(3,numel(d)); % Initialize
for i = 1:numel(d)
Bi = B.*[1;d(i);0]; % Create a new B each iteration for a new d
F(:,i)=linsolve(A,Bi);
end
plot(d,F)

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by