Info
Questa domanda è chiusa. Riaprila per modificarla o per rispondere.
Storing found values in array
    3 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
Hello I have a code set to do a bisection method. I need to store the values of a, b, c, x,and y for each iteration of the code so i can make a table and plot them. How would i go about doing that? 
clear; clc;
f=@(x)2 * x^4 +3 * x^3 - 11 * x^2 - 9 * x + 15 ; 
a=input('\n Enter left point of interval '); 
b=input('\n Enter right point of interval '); 
toll= 1e-4;  
 err=abs(b-a);
 c = ( a + b )/2;
 if f(a) *f(b) > 0 
    disp 'Enter valid interval!!!');
 else
      c = ( a + b) /2;
      toll= 1e-4;  
      err=abs(b-a);
      while err > toll
          if abs(f(c)) < err
          else 
    c = ( a + b )/2;
    x = abs( b - c);
    y = abs(f(c));
     if ( f(a) * f(c)) <= 0
        b = c;
   else
        if ( f(b) * f(c)) <= 0
            a = c;
        end
     end
          end
          c = ( a + b) /2;
          err = abs(b-a);
      end
      fprintf( 'The Root is: %4.4f\n', c)
 end
0 Commenti
Risposte (1)
  Fangjun Jiang
      
      
 il 30 Mar 2020
        I had this example code for answering a similar question. I think you can utilize it as an example for storing while-loop results.
x=100;y=200;
k=0;
result=ones(100,2);
while x>1e-3 && y>1e-4
    k=k+1
    [x,y]=D23(x,y);
    result(k,:)=[x,y];
end
result(k+1:end,:)=[]
function [x,y]=D23(x,y)
x=x/2;
y=y/3;
end
0 Commenti
Questa domanda è chiusa.
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

