Question about programming a for loop with two equations

I am working on a long code involving neutron stars and I have run into a snag. All I want to do is create a for loop in which I solve an equation for r. Before moving to the next ith iteration, I need to take that single solved value for r and plug it into another equation to solve for b. Then it can go back to the beginning and do the two equations over again with the next ith step. I seem to be having great difficulty programming this and I think it has something to do with how I am defining my variables. Here is that part of the code:
clear all;
p=input('TauesNtm1 Value?');
n=input('Nt Value?');
t=input('Taues1 Value?');
for i=(2:1:((n/2)-2)/1);
r(i)=.5*Log10((2*p)^((1 - 2*(i - 2))/(n - 4))*(t/2)^((2*(i - 2))/(n - 4)))+(i - 2)*(((n - 4)*p-2*p-.5*t)/(n - 4));
b(r(i))=.434294*(.190352 + 2.20509566529930*r+1.379117301391070*r^2-0.481593138241581*r^3- 0.2311271889879584*r^4+0.500820485853822*r^5-0.269537234996903*r^6-0.20063340749777*r^7+0.475894136618535*r^8-0.2831206627297433*r^9-0.2328164535174437*r^10+0.585886001688777*r^11-0.3690986055298708*r^12-0.310009361710399*r^13+0.817684785462915*r^14-0.537360306829214*r^15-0.447280339896678*r^16+1.229551315307617*r^17-0.836592197418212*r^18-0.679642677307128*r^19+1.942584991455078*r^20);
end
any ideas as to what I am doing wrong?

Risposte (1)

b(i) = .434294*(.190352 + 2.20509566529930*r+1.379117301391070*r(i)^2-0.481593138241581*r(i)^3 [etc]

Categorie

Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange

Tag

Richiesto:

il 21 Set 2012

Community Treasure Hunt

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

Start Hunting!

Translated by