Implicit function inside a loop.
Afficher commentaires plus anciens
I want to plot a curve between err and b for different values of b.
- I have kept the values of i to be a constant for the inner iteration, and I want to sum up the error ( square )
- In 'o' and 'p'for different values of 'i' and finally I want to plot err vs b. such that i get a minimum to this curve at a certain 'b'.
sum =0;
err =0;
for b= 0:1:40
for i= 0:1:50
f1 = @(o,i) (sind(b+i) + sind(b-o)) -( 1.180/0.04 + sqrt.((1.140/0.04 - 2*sind(b)).^2 - (cosd(b-o)- cosd(b+i)).^2));
f2 = @(p,i) cotd(p-3.34) - cotd(i-1.07) - (1.180/(1.540 - 0.300));
sum = sum + (o - p).^2;
end
err = sqrt(sum/50);
plot (b,err);
hold on
end
1 commentaire
Anshuman S
le 21 Jan 2018
Réponses (1)
Walter Roberson
le 21 Jan 2018
total = 0;
err = 0;
bvals = 0:1:40;
for b = bvals
subtotal = 0;
for i= 0:1:50
f1 = @(o,i) (sind(b+i) + sind(b-o)) -( 1.180/0.04 + sqrt.((1.140/0.04 - 2*sind(b)).^2 - (cosd(b-o)- cosd(b+i)).^2));
f2 = @(p,i) cotd(p-3.34) - cotd(i-1.07) - (1.180/(1.540 - 0.300));
subtotal = subtotal + (o - p).^2;
end
err = sqrt(subtotal/50);
plot(bvals,err);
hold on
total = total + subtotal;
end
But why do you define f1 and f2 when you do not use them? And you have not defined o or p but you try to add their squared difference to the total?
3 commentaires
Image Analyst
le 21 Jan 2018
And even if you did use them, why do you want them to be defined inside a loop instead of at the top of your program?
And don't use sum as the name of your variable since it's a built in function.
Anshuman S
le 21 Jan 2018
Anshuman S
le 21 Jan 2018
Catégories
En savoir plus sur Fit Postprocessing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!