Solving two equations simultaneously then plotting
Show older comments
Hi, I have only ever used matlab at a beginner level and havent touched it in a while. What I am trying to do is to solve an equation for a specific variable. Once this is done, another variable from the equation needs to be adjusted, and then the equation needs to be solved again. I want to record these results in an array so that they can both be plotted against time so that I can see how the variables evolve. Simultaneously, I need to use these calculated values as part of a second seperate equation to find another two variables, both of which I would also like to plot. I am trying to write some pseudocode so that I can get my head around this. It is likely not a very complicated thing to code, however I am strugling and would appreciate any help and advice. Thanks in advance!
Answers (1)
For the first part, see if somoething like this would work —
n = 1:10;
m = 1:5;
[N,M] = ndgrid(n,m);
f = @(x,n,m) m.*x.^2 - n;
for k1 = 1:numel(n)
for k2 = 1:numel(m)
rp(k1,k2) = fzero(@(x)f(x,n(k1),m(k2)), rand); % Calculate Positive Root
end
end
rp
Here, both variables are changed inside the nested loops, and the result saved to a matrix.
.
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!